Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Check for MCP Available Attributes #3232

Merged
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
103 changes: 60 additions & 43 deletions core/context/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ class MCPConnectionSingleton {
}
}

async checkClientAttribute(func: () => Promise<any>): Promise<any> {
try {
const result = await func();
return result;
} catch (e) {
return null;
}
}

async modifyConfig(config: ContinueConfig): Promise<ContinueConfig> {
try {
await this.connectClient();
Expand All @@ -97,58 +106,66 @@ class MCPConnectionSingleton {
}
}

// Resources <—> Context Provider
const { resources } = await this.client.listResources();
const capabilities = this.client.getServerCapabilities();

const submenuItems = resources.map((resource: any) => ({
title: resource.name,
description: resource.description,
id: resource.uri,
}));
// Resources <—> Context Provider
if (capabilities?.resources) {
const { resources } = await this.client.listResources();
const submenuItems = resources.map((resource: any) => ({
title: resource.name,
description: resource.description,
id: resource.uri,
}));

if (!config.contextProviders) {
config.contextProviders = [];
}

if (!config.contextProviders) {
config.contextProviders = [];
config.contextProviders.push(
new MCPContextProvider({
submenuItems,
client: this.client,
}),
);
}

config.contextProviders!.push(
new MCPContextProvider({
submenuItems,
client: this.client,
}),
);

// Tools <—> Tools
const { tools } = await this.client.listTools();
const continueTools: Tool[] = tools.map((tool) => ({
displayTitle: tool.name,
function: {
description: tool.description,
name: tool.name,
parameters: tool.inputSchema,
},
readonly: false,
type: "function",
wouldLikeTo: `use the ${tool.name} tool`,
uri: `mcp://${tool.name}`,
}));

config.tools = [...config.tools, ...continueTools];
if (capabilities?.tools) {
const { tools } = await this.client.listTools();
const continueTools: Tool[] = tools.map((tool: any) => ({
displayTitle: tool.name,
function: {
description: tool.description,
name: tool.name,
parameters: tool.inputSchema,
},
readonly: false,
type: "function",
wouldLikeTo: `use the ${tool.name} tool`,
uri: `mcp://${tool.name}`,
}));

config.tools = [...config.tools, ...continueTools];
}

// Prompts <—> Slash commands
const { prompts } = await this.client.listPrompts();
if (!config.slashCommands) {
config.slashCommands = [];
}
if (capabilities?.prompts) {
const { prompts } = await this.client.listPrompts();
if (!config.slashCommands) {
config.slashCommands = [];
}

const slashCommands: SlashCommand[] = prompts.map((prompt) => {
return constructMcpSlashCommand(
this.client,
prompt.name,
prompt.description,
prompt.arguments?.map((a) => a.name),
const slashCommands: SlashCommand[] = prompts.map((prompt: any) =>
constructMcpSlashCommand(
this.client,
prompt.name,
prompt.description,
prompt.arguments?.map((a: any) => a.name),
),
);
});
config.slashCommands!.push(...slashCommands);

config.slashCommands.push(...slashCommands);
}

return config;
}
Expand Down
20 changes: 10 additions & 10 deletions core/tools/builtIn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export enum BuiltInToolNames {
ReadFile = "read_file",
ReadCurrentlyOpenFile = "read_currently_open_file",
CreateNewFile = "create_new_file",
RunTerminalCommand = "run_terminal_command",
ViewSubdirectory = "view_subdirectory",
ViewRepoMap = "view_repo_map",
ExactSearch = "exact_search",
SearchWeb = "search_web",
ViewDiff = "view_diff",
}
ReadFile = "builtin_read_file",
ReadCurrentlyOpenFile = "builtin_read_currently_open_file",
CreateNewFile = "builtin_create_new_file",
RunTerminalCommand = "builtin_run_terminal_command",
ViewSubdirectory = "builtin_view_subdirectory",
ViewRepoMap = "builtin_view_repo_map",
ExactSearch = "builtin_exact_search",
SearchWeb = "builtin_search_web",
ViewDiff = "builtin_view_diff",
}
Loading