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()
- The agent connects over streamable HTTP, the default transport. You never configure it for this server.
- 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 take a while on a big repository. One tool call may run for tool_timeout seconds, 120 by default; raise it with mcp_config=MCPConnection(url="https://mcp.deepwiki.com/mcp", tool_timeout=300). mcp_timeout only bounds connecting and sending requests.cannot import name 'streamablehttp_client'
cannot import name 'streamablehttp_client'
Your
swarms predates mcp 2.x support, which renamed that function. Upgrade with pip install -U swarms; 15.0.1 and later work with both mcp 1.x and 2.x.Next
- GitMCP — scope a server to one repository.
- Several servers at once — combine DeepWiki with Microsoft Learn.