Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 91 additions & 9 deletions mcp-servers/mcp-server-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ import { z } from 'zod';
import packageJson from '../package.json';
import { codeCheckerTool } from './tools/code_checker';
import {
getCallStack,
getCallStackSchema,
getStackFrameVariables,
getStackFrameVariablesSchema,
listDebugSessions,
listDebugSessionsSchema,
resumeDebugSession,
resumeDebugSessionSchema,
setBreakpoint,
setBreakpointSchema,
startDebugSession,
startDebugSessionSchema,
stopDebugSession,
Expand Down Expand Up @@ -153,19 +161,50 @@ export const activate = async (context: vscode.ExtensionContext) => {
},
);

// Register 'stop_debug_session' tool
// Register 'set_breakpoint' tool
mcpServer.tool(
'set_breakpoint',
'Set a breakpoint at a specific line in a file.',
setBreakpointSchema.shape,
async (params) => {
const result = await setBreakpoint(params);
return {
...result,
content: result.content.map((item) => ({
...item,
type: 'text' as const,
})),
};
},
);

// Register 'restart_debug_session' tool
// Register 'get_call_stack' tool
mcpServer.tool(
'restart_debug_session',
'Restart a debug session by stopping it and then starting it with the provided configuration.',
startDebugSessionSchema.shape, // using the same schema as 'start_debug_session'
'get_call_stack',
'Get the current call stack information for an active debug session.',
getCallStackSchema.shape,
async (params) => {
// Stop current session using the provided session name
await stopDebugSession({ sessionName: params.configuration.name });
const result = await getCallStack(params);
return {
...result,
content: result.content.map((item) => {
if ('json' in item) {
// Convert json content to text string
return { type: 'text' as const, text: JSON.stringify(item.json) };
}
return { ...item, type: 'text' as const };
}),
};
},
);

// Then start a new debug session with the given configuration
const result = await startDebugSession(params);
// Register 'resume_debug_session' tool
mcpServer.tool(
'resume_debug_session',
'Resume execution of a debug session that has been paused (e.g., by a breakpoint).',
resumeDebugSessionSchema.shape,
async (params) => {
const result = await resumeDebugSession(params);
return {
...result,
content: result.content.map((item) => ({
Expand All @@ -175,6 +214,28 @@ export const activate = async (context: vscode.ExtensionContext) => {
};
},
);

// Register 'get_stack_frame_variables' tool
mcpServer.tool(
'get_stack_frame_variables',
'Get variables from a specific stack frame in a debug session.',
getStackFrameVariablesSchema.shape,
async (params) => {
const result = await getStackFrameVariables(params);
return {
...result,
content: result.content.map((item) => {
if ('json' in item) {
// Convert json content to text string
return { type: 'text' as const, text: JSON.stringify(item.json) };
}
return { ...item, type: 'text' as const };
}),
};
},
);

// Register 'stop_debug_session' tool
mcpServer.tool(
'stop_debug_session',
'Stop all debug sessions that match the provided session name.',
Expand All @@ -191,6 +252,27 @@ export const activate = async (context: vscode.ExtensionContext) => {
},
);

// Register 'restart_debug_session' tool
mcpServer.tool(
'restart_debug_session',
'Restart a debug session by stopping it and then starting it with the provided configuration.',
startDebugSessionSchema.shape, // using the same schema as 'start_debug_session'
async (params) => {
// Stop current session using the provided session name
await stopDebugSession({ sessionName: params.configuration.name });

// Then start a new debug session with the given configuration
const result = await startDebugSession(params);
return {
...result,
content: result.content.map((item) => ({
...item,
type: 'text' as const,
})),
};
},
);

// Set up an Express app to handle SSE connections
const app = express();
const mcpConfig = vscode.workspace.getConfiguration('mcpServer');
Expand Down
110 changes: 110 additions & 0 deletions mcp-servers/mcp-server-vscode/src/tools/debug_tools.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,113 @@ export declare const stopDebugSessionSchema: z.ZodObject<{
}, {
sessionName: string;
}>;
export declare const setBreakpoint: (params: {
filePath: string;
line: number;
}) => Promise<{
content: {
type: string;
text: string;
}[];
isError: boolean;
}>;
export declare const setBreakpointSchema: z.ZodObject<{
filePath: z.ZodString;
line: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
filePath: string;
line: number;
}, {
filePath: string;
line: number;
}>;
export declare const getCallStack: (params: {
sessionName?: string;
}) => Promise<{
content: {
type: string;
text: string;
}[];
isError: boolean;
} | {
content: {
type: string;
json: {
callStacks: ({
sessionId: string;
sessionName: string;
threads: any[];
error?: undefined;
} | {
sessionId: string;
sessionName: string;
error: string;
threads?: undefined;
})[];
};
}[];
isError: boolean;
}>;
export declare const getCallStackSchema: z.ZodObject<{
sessionName: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
sessionName?: string | undefined;
}, {
sessionName?: string | undefined;
}>;
export declare const resumeDebugSession: (params: {
sessionId: string;
}) => Promise<{
content: {
type: string;
text: string;
}[];
isError: boolean;
}>;
export declare const resumeDebugSessionSchema: z.ZodObject<{
sessionId: z.ZodString;
}, "strip", z.ZodTypeAny, {
sessionId: string;
}, {
sessionId: string;
}>;
export declare const getStackFrameVariables: (params: {
sessionId: string;
frameId: number;
threadId: number;
filter?: string;
}) => Promise<{
content: {
type: string;
text: string;
}[];
isError: boolean;
} | {
content: {
type: string;
json: {
sessionId: string;
frameId: number;
threadId: number;
variablesByScope: any[];
filter: string | undefined;
};
}[];
isError: boolean;
}>;
export declare const getStackFrameVariablesSchema: z.ZodObject<{
sessionId: z.ZodString;
frameId: z.ZodNumber;
threadId: z.ZodNumber;
filter: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
sessionId: string;
frameId: number;
threadId: number;
filter?: string | undefined;
}, {
sessionId: string;
frameId: number;
threadId: number;
filter?: string | undefined;
}>;
Loading