Example - Connecting to MCP server hosted via "npx" & implement it for Claude Python API #36
ArsenicBismuth
started this conversation in
Show and tell
Replies: 3 comments 6 replies
|
Most of the documentation talks about the servers, and not much about the client. UPDATE: I show my full implementation in the comment below. |
5 replies
|
Are you on Windows by chance? There's a known issue with Regardless, will close this out as resolved. Thanks for documenting your solution! |
1 reply
|
As for npx path problem, my workaround is like bellow: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I got stuck on this quite a bit so I wanted to share my solution. I'm trying to connect Brave Web Search to my custom AI assistant (using Anthropic's Python API). Turns out I got various issues supplying
"npx"directly to the command list.What you should do is using
shutil.which()like below:Also note that you can't pass
envwith dict containing the API key directly, becausenpxcommand requires some other env variables. So, whileNonewould work to call thenpxcommand, you can't pass your API key in here.If the maintainer doesn't mind, I can make a PR to add this example to the README.
UPDATE: You can check the detailed information in the comments.
To sum it up, after you initialized the parameters for the server:
tool_use, then call the tool with its inputDo note, to call a tool, the connection MUST be maintained. Which is why I need the session context before calling the tool.
All reactions