home / mcp / python mcp server
A Python-based MCP server that retrieves and cleans official docs for AI/library ecosystems.
Configuration
View docs{
"mcpServers": {
"aiwithhassan-mcp-server-python": {
"command": "uv",
"args": [
"run",
"mcp_server.py"
],
"env": {
"GROQ_API_KEY": "YOUR_GROQ_API_KEY",
"SERPER_API_KEY": "YOUR_SERPER_API_KEY"
}
}
}
}You have a lightweight MCP server written in Pythonthat uses FastMCP to expose a tool for retrieving and cleaning official documentation content for popular AI and Python ecosystem libraries. It runs over stdio via uv, is designed for streaming-safe operation, and returns a traceable, source-labeled text blob suitable for augmentation with an LLM.
You interact with the server through an MCP client. Start the server, list available tools, and invoke the documentation tool to fetch and clean official docs for a specific library. The primary tool is get_docs, which returns a concatenated, source-labeled text block that you can feed into an LLM for user-facing answers.
Prerequisites: Python 3.11 or newer and the UV package manager/runtime.
1) Install UV and set up the environment.
2) Prepare your project environment and dependencies.
3) Create a project environment and install dependencies as described in your setup.
Run the MCP server using the following command to start listening on stdio. This registers the get_docs tool for client usage.
uv run mcp_server.pyTo interact from a client, use the provided client script. It lists tools, calls get_docs, and passes the result to an LLM for a user-friendly answer.
uv run client.pyEnvironment variables control access to the external services used for scraping and cleaning. Create a .env file at the project root with the required keys.
SERPER_API_KEY=your_serper_api_key_here
GROQ_API_KEY=your_groq_api_key_hereIf you encounter issues, enable logging to stderr to diagnose problems without polluting stdout used for JSON-RPC.
import logging, sys
logging.basicConfig(level=logging.INFO, stream=sys.stderr)The server focuses on retrieving documentation content restricted to official docs domains relevant to the libraries in use. It exposes a single tool named get_docs that takes a query and a library key and returns a clean, source-labeled text blob suitable for augmentation with an LLM.
Tool to retrieve and clean official documentation sections for a given library. Returns a concatenated, source-labeled text blob suitable for retrieval-augmented prompting.