Example - Connecting to MCP server hosted via "npx" & implement it for Claude Python API #36
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. |
Beta Was this translation helpful? Give feedback.
-
Are you on Windows by chance? There's a known issue with Regardless, will close this out as resolved. Thanks for documenting your solution! |
Beta Was this translation helpful? Give feedback.
-
As for npx path problem, my workaround is like bellow:
|
Beta Was this translation helpful? Give feedback.
-
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
env
with dict containing the API key directly, becausenpx
command requires some other env variables. So, whileNone
would work to call thenpx
command, 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.
Beta Was this translation helpful? Give feedback.
All reactions