tool-agent-demo
Provides a tool to search a GitHub user's public repositories, filtering by substring match on name or description and limiting results, using the live GitHub REST API.
Provides a tool to query a local SQLite book database with filters such as author, genre, minimum year, and minimum rating, returning results ordered by rating.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@tool-agent-demoFind fantasy books rated above 4.3 in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-tool-agent
A minimal end-to-end demonstration of the Model Context Protocol (MCP): one MCP server exposing three real tools, and a command-line agent that lets an LLM decide which tool to call and invokes it over the protocol.
Tool calls always travel through MCP (tools/list + tools/call over a
stdio JSON-RPC connection). The agent never imports the tool functions
directly.
See ARCHITECTURE.md for the design choices and the security model.
The server
server.py is a FastMCP server named tool-agent-demo that speaks over
stdio. It exposes three tools:
Tool | Description | Inputs |
| Lists a GitHub user's public repos, filtered by a substring match on name/description. Calls the live GitHub REST API, following pagination up to 10 pages. |
|
| Fetches a web page and returns its visible text (scripts/styles/nav stripped) plus the title. Refuses non-public hosts (enforced at connection time, pinned to the validated IP), oversized responses, and non-text content. |
|
| Queries a local SQLite database of 20 books. Filters are AND-combined; results ordered by rating descending. |
|
Each tool's input schema is generated from its typed signature and returned
in tools/list.
It also exposes two resources: books://schema (the catalog's columns)
and books://catalog (the full catalog as JSON).
Related MCP server: github-repos
The agent
agent.py takes a natural-language question and:
Spawns
server.pyand connects over stdio with the MCP client.Runs the
initializehandshake, thentools/list.Runs
resources/listand reads the small ones (the schema) into the system prompt.Converts the MCP tool definitions into the LLM's tool-calling format.
Asks the LLM (OpenAI,
gpt-4o-miniby default) to answer, with the tools available.For each tool call the model returns, executes it via
tools/calland feeds the result back. Bad tool arguments and protocol errors are turned into text the model can react to.On the final turn the tools are withheld so the model must answer from what it has.
Prints the model's answer.
Transient LLM errors are retried with backoff. Every protocol step and token
usage is logged to stderr with an [agent] prefix.
python agent.py [--model MODEL] [--max-turns N] "your question"Setup
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # then set OPENAI_API_KEY
python seed_books.py # creates books.db.env keys:
OPENAI_API_KEY– required by the agent.OPENAI_MODEL– optional, defaults togpt-4o-mini.OPENAI_TEMPERATURE– optional, defaults to0; set tononeto omit the field.AGENT_MAX_TURNS– optional, defaults to5.GITHUB_TOKEN– optional, raises the GitHub API rate limit.
Installing the package (pip install -e .) also puts a mcp-tool-agent
command on your path, equivalent to python agent.py.
Running
python agent.py "Which fantasy books in the database are rated above 4.3?"
python agent.py "Find repos owned by 'tiangolo' related to 'fastapi', top 3 by stars."
python agent.py "Fetch https://peps.python.org/pep-0020/ and list three aphorisms."To exercise the server on its own without an LLM:
python - <<'EOF'
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
params = StdioServerParameters(command="./venv/bin/python", args=["server.py"])
async with stdio_client(params) as (r, w):
async with ClientSession(r, w) as s:
await s.initialize()
print([t.name for t in (await s.list_tools()).tools])
res = await s.call_tool("query_books", {"genre": "fantasy", "min_rating": 4.4})
print(res.content[0].text)
asyncio.run(main())
EOFRecorded runs against all three tools, plus error paths (unknown user, unreachable/404/non-http URLs, missing database, schema validation), are in TEST_RUN.md.
Tests
pip install -r requirements-dev.txt
python seed_books.py
ruff check .
mypy server.py agent.py seed_books.py
pytest -q --covThe suite covers the tool logic with mocked HTTP, the SSRF pre-check and the
connection-time backend guard (including IP pinning), resources/list and
resources/read, a real stdio round-trip that spawns the server, and
agent.run() driven by a scripted LLM against that real server. CI runs
ruff, mypy, and the suite on Python 3.11–3.13.
Notes
Pinned to
mcp==1.29.x(the 1.xFastMCPAPI). The 2.x release renames the server class and changes several APIs.No secrets are committed;
.envandbooks.dbare gitignored.
This server cannot be deployed
Maintenance
Related MCP Connectors
Search GitHub, npm, PyPI, StackOverflow, ArXiv from one MCP — built for coding agents.
Turn a GitHub repo or docs site into agent-ready context: pack it or search it, over MCP.
Web search, scraping, RAG answers with citations, and translation as MCP tools.
An MCP server that gives your AI access to the source code and docs of all public github repos
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables natural-language analysis of GitHub repositories by exposing repository metadata, source code retrieval, search, and file reading as MCP tools, with answers grounded in the actual repository content.-
- FlicenseNot gradedqualityCmaintenanceEnables read-only browsing and querying of GitHub repositories, including listing repos, reading files, fetching READMEs, searching code, and viewing commit history via MCP.-
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to interact with GitHub repositories and issues through MCP tools, supporting listing repositories, listing and searching issues, and retrieving specific issues via the GitHub REST API.-
- FlicenseNot gradedqualityCmaintenanceEnables large language models to explore, inspect, and analyze GitHub repositories through natural-language queries, using MCP tools to retrieve repository data, file structures, file contents, and code search results from the GitHub REST API.-