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

Bug with MCP context provider resource reading #3647

Open
3 tasks done
leaft opened this issue Jan 8, 2025 · 3 comments
Open
3 tasks done

Bug with MCP context provider resource reading #3647

leaft opened this issue Jan 8, 2025 · 3 comments
Assignees
Labels
area:context-providers Relates to context providers area:mcp Relates to Model Context Protocol (MCP) area:tools Relates to tool usage kind:bug Indicates an unexpected problem or unintended behavior

Comments

@leaft
Copy link
Contributor

leaft commented Jan 8, 2025

Before submitting your bug report

Relevant environment info

- OS: macOS
- Continue version: 0.9.250
- IDE version: 1.96.2
- Model: any
- config.json: the mcp config
  
  "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-postgres",
            "postgresql://postgres@localhost/postgres"
          ]
        }
      }
    ]
  },

Description

I found a bug related to mcp context provider, the source code pieces are below

async loadSubmenuItems(
args: LoadSubmenuItemsArgs,
): Promise<ContextSubmenuItem[]> {
return (this.options as MCPContextProviderOptions).submenuItems;
}
}

const { mcpId, uri } = MCPContextProvider.decodeMCPResourceId(query);

static decodeMCPResourceId(mcpResourceId: string): {
mcpId: string;
uri: string;
} {
return JSON.parse(mcpResourceId);
}

To make it concise, the main problem is the mcp server uri, which exposed by the mcp server, will be directly used as the mcp context provider's options.submenuItems.id, and when you input @mcp and select the resource, the query is actually a uri string, but not a json string, which will then fail in JSON.parse and the error appears (in the right bottom of vscode, as the image below shows).
Since the mcpId is allocated innerly, so change the mcp server's code is useless. Currently, a simple way to fix the problem is to make the loadSubmenuItems return right id string. I have tested the change and confirmed the code could work in this case, but I haven't tested it thoroughly.

async loadSubmenuItems(
    args: LoadSubmenuItemsArgs,
  ): Promise<ContextSubmenuItem[]> {
    return (this.options as MCPContextProviderOptions).submenuItems.map((item, index) => ({
      ...item,
      id: JSON.stringify({
        mcpId: String(index),
        uri: item.id,
      })
    }));
  }

Glad if this can help.

To reproduce

Make your mcp config is right, and the select a mcp context, chat
截屏2025-01-08 11 26 45

Log output

No response

@dosubot dosubot bot added area:context-providers Relates to context providers kind:bug Indicates an unexpected problem or unintended behavior labels Jan 8, 2025
@Patrick-Erichsen Patrick-Erichsen added area:mcp Relates to Model Context Protocol (MCP) area:tools Relates to tool usage labels Jan 8, 2025
@Patrick-Erichsen
Copy link
Collaborator

The fix you proposed makes sense to me. If you don't mind opening a PR with the fix we'd love to get this merged!

@leaft
Copy link
Contributor Author

leaft commented Jan 9, 2025

Fine, I will make a PR soon.

@leaft
Copy link
Contributor Author

leaft commented Jan 9, 2025

The fix you proposed makes sense to me. If you don't mind opening a PR with the fix we'd love to get this merged!

Done with #3662
I can provide proper help if need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:context-providers Relates to context providers area:mcp Relates to Model Context Protocol (MCP) area:tools Relates to tool usage kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants