Prerequisites
- Python 3.10+
- One LLM provider key. This tutorial uses Anthropic; any LiteLLM model with tool-calling support works.
Build it
1
Install swarms
2
Set your LLM key
3
Write a system prompt that forces grounding
An agent with a research tool will still answer from memory unless you tell it not to. This prompt is the difference between a citation and a guess:
4
Point the agent at the server
mcp_url is the entire integration. On startup the agent connects, fetches the server’s tool list, and converts each tool into a function-calling schema the model can use.5
Run a task
The complete script
What happens when you call run()
- Transport is detected from the URL scheme. An
https://URL uses streamable HTTP; you never configure this by hand. - Tools are discovered. The agent asks the server what it exposes and converts each tool to an OpenAI-format function schema.
- The model chooses. It typically calls
read_wiki_structureto see what exists, thenread_wiki_contentsorask_questionfor the parts that matter. - Results come back into the conversation, and the model writes its answer from them.
The smallest possible version
Strip the system prompt and you still have a working integration — useful for a first smoke test:Troubleshooting
The agent answers without calling a tool
The agent answers without calling a tool
Two fixes, in order: say “use your tools” in the task, and put the instruction to retrieve before answering in the system prompt. Weaker models need both.
Timeouts on large repositories
Timeouts on large repositories
read_wiki_contents can return a lot of text. Raise the ceiling with mcp_timeout=120 on the Agent.cannot import name 'streamablehttp_client'
cannot import name 'streamablehttp_client'
You are on
mcp 2.x, which renamed it. Pin the 1.x line: pip install 'mcp>=1.28.1,<2.0.0'.Next
- GitMCP — scope a server to one repository.
- Several servers at once — combine DeepWiki with Microsoft Learn.