Skip to main content
Glama

nanomcp

Dies ist eine minimale MCP-Demo, die ohne das MCP Python SDK von Hand geschrieben wurde. Sie umfasst die vollständige Kette:

  1. nanomcp.server fungiert als MCP-Server und sendet/empfängt JSON-RPC über stdio.

  2. nanomcp.cli fungiert als MCP-Client/Host, startet den Server und führt initialize, tools/list und tools/call aus.

  3. Der chat-Befehl ruft OpenAI Chat Completions auf. Nachdem das Modell einen Funktions-/Tool-Aufruf zurückgibt, wandelt die CLI diesen in einen MCP tools/call um und sendet das Werkzeugergebnis zurück an das Modell, um die endgültige Antwort zu generieren.

Die Beziehung zwischen MCP und Funktionsaufrufen

Kurz gesagt: Funktionsaufrufe sind eine Modell-API-Fähigkeit, bei der „das Modell Ihrer Anwendung mitteilt, welche Funktion es aufrufen möchte“; MCP ist ein Verbindungsprotokoll, das festlegt, „wie Ihre Anwendung externe Tools/Kontextdienste über ein einheitliches Protokoll entdeckt und aufruft“.

Genauer gesagt:

  • Funktions-/Tool-Aufrufe finden zwischen LLM API <-> Ihrer Anwendung statt. Das Modell führt die Funktion nicht wirklich aus, es gibt nur eine Aufrufabsicht wie {"name":"get_weather","arguments":{...}} zurück.

  • MCP findet zwischen Ihrer Anwendung <-> MCP-Server statt. Der MCP-Server stellt eine Liste von Tools und Einstiegspunkte für die Ausführung bereit, wie z. B. tools/list und tools/call.

  • Der Host/Client ist der Vermittler. Er ruft zuerst das Tool-Schema vom MCP-Server ab, wandelt diese Schemas in Tools für die Modell-API um; nachdem das Modell ein Tool ausgewählt hat, ruft der Host/Client den MCP-Server auf.

Die Kette in diesem Projekt ist:

用户问题
  -> nanomcp.cli
  -> OpenAI Chat Completions tools=function schemas
  <- 模型返回 tool_calls
  -> nanomcp.cli 把 tool_call 映射为 MCP tools/call
  -> nanomcp.server 执行 get_weather 或 find_files
  <- MCP tool result
  -> nanomcp.cli 把结果发回模型
  <- 模型最终回答

Sie befinden sich also nicht auf derselben Ebene:

Function call: 模型 API 的工具选择/参数生成机制
MCP: 应用连接工具服务器的标准协议

Related MCP server: MCP Server Demo

Dateistruktur

nanomcp/
  nanomcp/
    cli.py       # MCP client + model caller
    server.py    # hand-written MCP server over stdio
  tests/
    test_protocol.py
  pyproject.toml
  README.md

MCP direkt ausführen, ohne das Modell aufzurufen

Führen Sie im Projektverzeichnis aus:

cd ~/Desktop/nanomcp
python3 -m nanomcp.cli list-tools

Direkter Aufruf des Wetter-Tools:

python3 -m nanomcp.cli call get_weather '{"location":"Shanghai","unit":"celsius"}'

Direkter Aufruf des Tools für das aktuelle Datum und die Uhrzeit:

python3 -m nanomcp.cli call get_current_datetime '{"timezone":"Asia/Shanghai"}'

Direkter Aufruf des Dateisuch-Tools:

python3 -m nanomcp.cli call find_files '{"query":"*.pdf","max_results":5}'

Standardmäßig wird nur ~/Desktop durchsucht. Sie können das Suchstammverzeichnis vorübergehend erweitern oder verkleinern:

NANOMCP_FILE_ROOT=~/Desktop/nanomcp python3 -m nanomcp.cli call find_files '{"query":"*.py"}'

Die vollständige Modell + MCP-Kette ausführen

Sie benötigen einen OpenAI API-Key. Hier wird nicht das OpenAI Python SDK verwendet, sondern die Standardbibliothek urllib, um HTTP-Anfragen direkt zu senden.

Es wird empfohlen, die lokale Konfiguration in .env zu schreiben:

cd ~/Desktop/nanomcp
cp .envtemplate .env

Bearbeiten Sie dann .env:

OPENAI_API_KEY=你的 key
OPENAI_BASE_URL=https://api.openai.com/v1
NANOMCP_MODEL=gpt-4.1-mini
NANOMCP_TIMEZONE=Asia/Shanghai

.env wird automatisch von der CLI gelesen und wurde bereits von .gitignore ignoriert.

cd ~/Desktop/nanomcp
python3 -m nanomcp.cli chat "上海今天天气怎么样?顺便帮我找桌面上的 PDF 文件"

Das Standardmodell ist gpt-4.1-mini. Sie können es ändern:

NANOMCP_MODEL=gpt-5-mini python3 -m nanomcp.cli chat "找一下这个项目里的 py 文件"

Wenn Sie ein OpenAI-kompatibles Gateway verwenden:

OPENAI_BASE_URL=http://localhost:8000/v1 python3 -m nanomcp.cli chat "上海天气怎么样?"

Leichte Überprüfung der lokalen Konfiguration und des MCP-Servers:

python3 -m nanomcp.cli doctor

Fehlerbehebung

Wenn chat OpenAI API quota is exhausted (429 insufficient_quota) ausgibt, bedeutet dies, dass die Modell-API die Anfrage abgelehnt hat: Das Projekt, zu dem der OPENAI_API_KEY gehört, hat kein verfügbares Guthaben oder die Abrechnung ist nicht aktiviert. Dies ist kein Fehler des MCP-Servers, da die Anfrage abgelehnt wurde, bevor das Modell einen Tool-Aufruf zurückgeben konnte.

Reihenfolge der Fehlerbehebung:

python3 -m nanomcp.cli doctor
echo "$OPENAI_API_KEY"
cat .env
python3 -m nanomcp.cli call get_weather '{"location":"Shanghai"}'
OPENAI_BASE_URL=http://localhost:8000/v1 python3 -m nanomcp.cli chat "上海天气怎么样?"
  • Der erste Befehl zeigt maskiert die gültige Konfiguration an, ob die Shell .env überschreibt und ob der MCP-Server Tools auflisten kann.

  • Der zweite Befehl bestätigt, ob der Key in der Shell bereits gesetzt ist.

  • Der dritte Befehl bestätigt die lokale Konfiguration in .env.

  • Der vierte Befehl überprüft, ob die lokale MCP-Kette normal funktioniert, ohne von der Modell-API abhängig zu sein.

  • Der fünfte Befehl demonstriert, wie man auf ein OpenAI-kompatibles Gateway wechselt.

  • Wenn Sie weiterhin die offizielle OpenAI-API verwenden, müssen Sie einen Key/ein Projekt mit Guthaben verwenden oder die Abrechnung und Modellberechtigungen überprüfen.

Optionales echtes Wetter

Das Standardwetter ist deterministische Demo-Daten, was das Erlernen der Protokollkette ohne Netzwerk oder Drittanbieter-Keys erleichtert. Um eine echte Abfrage auszuprobieren:

NANOMCP_LIVE_WEATHER=1 python3 -m nanomcp.cli call get_weather '{"location":"Shanghai"}'

Das echte Wetter verwendet https://wttr.in und greift bei einem Fehler automatisch auf Demo-Daten zurück.

Testen

cd ~/Desktop/nanomcp
python3 -m unittest discover -s tests

Testabdeckung:

  • MCP initialize

  • MCP tools/list

  • MCP tools/call get_weather

  • MCP tools/call find_files

  • MCP tools/call get_current_datetime

Wichtige Beobachtungen

Sehen Sie sich openai_tools_from_mcp() in nanomcp/cli.py an: Es wandelt das MCP-Tool-Schema in das OpenAI-Funktions-Tool-Schema um.

Sehen Sie sich run_chat() an: Es ruft mcp.call_tool() auf, nachdem es tool_calls vom Modell erhalten hat. Dies ist der Verbindungspunkt zwischen MCP und Funktionsaufrufen.

Sehen Sie sich main() in nanomcp/server.py an: Es liest nur von stdin und schreibt nach stdout, wobei jede Zeile JSON-RPC ist. Der Server kennt OpenAI nicht und hat keinen direkten Kontakt zum Modell.

Available Tools

3 tools
find_filesLocal file finderB

Find local files by name under the allowed root. The default root is ~/Desktop. Set NANOMCP_FILE_ROOT to change it.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesFilename substring or glob pattern, such as *.pdf.
rootNoOptional subdirectory under NANOMCP_FILE_ROOT.
max_resultsNo

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions the root directory and default, but it does not disclose important behaviors such as case sensitivity, recursion depth, glob pattern handling, permissions, or the structure of returned results.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise: two sentences. The first sentence states purpose and scope, the second provides configuration info. Every sentence adds value with no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there is no output schema, the description should hint at return format or behavior. It does not mention what is returned (file paths, metadata), sorting, recursion, or error handling. The tool is simple but the agent may need more context for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already describes two of three parameters (query and root). The description adds context about the root default and environment variable configuration, but does not enhance understanding of max_results or clarify glob pattern syntax beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function: 'Find local files by name under the allowed root.' It specifies the scope (local files) and the constraint (under a root). The siblings are unrelated (datetime and weather), so there is no ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no explicit guidance on when to use this tool versus alternatives. It does not mention when not to use it or any prerequisites. Given that siblings are unrelated, implicit guidance is minimal.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_current_datetimeCurrent date and timeA

Get the current date, time, and weekday. Use this for questions about today, current time, current date, or weekday.

ParametersJSON Schema
NameRequiredDescriptionDefault
timezoneNoIANA timezone name, such as Asia/Shanghai or America/New_York. Defaults to NANOMCP_TIMEZONE or Asia/Shanghai.Asia/Shanghai

TDQS

A4.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries full burden. It adequately describes the output (date, time, weekday) and timezone parameter. However, it does not mention that the operation is read-only, instantaneous, or any potential dependencies, leaving some behavioral details implicit.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, concise and front-loaded with the core function. Every sentence serves a purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (one optional parameter, no output schema), the description fully covers what the tool does, its possible output, and appropriate use cases. No gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With full schema coverage (100%), the description adds no new parameter details beyond the schema. The schema already describes the timezone parameter well, so the description provides minimal added value, meeting the baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool retrieves current date, time, and weekday. It explicitly lists use cases like 'today, current time, current date, or weekday', and siblings are unrelated, making purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description directly states when to use the tool ('for questions about today, current time, current date, or weekday'). It does not provide exclusions or alternatives, but given the simplicity and distinct siblings, this is sufficient.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_weatherWeather lookupA

Get current weather for a city. By default this returns deterministic demo data. Set NANOMCP_LIVE_WEATHER=1 to try wttr.in.

ParametersJSON Schema
NameRequiredDescriptionDefault
locationYesCity or place name, for example Shanghai.
unitNoTemperature unit.celsius

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the burden. It discloses the demo/live behavior and environment variable, but lacks details on return format, error handling, or external API dependencies.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences efficiently define purpose and critical behavioral context. No superfluous text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple weather tool, the description covers core purpose and key behavioral nuance. However, it omits return value structure or typical properties, which would help the agent understand the output.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema covers 100% of parameters with descriptions. The description adds no additional parameter meaning beyond what the schema provides, meeting baseline.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Get current weather for a city,' using a specific verb and resource, and distinguishes from siblings like find_files and get_current_datetime.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explains the default demo mode and how to switch to live data, providing context for when to expect real or synthetic data. No explicit alternatives or exclusions but sufficient for this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.1.0
    • First observedfind_files
    • First observedget_current_datetime
    • First observedget_weather

TDQS

A3.7/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a clear, distinct purpose: file search, datetime, and weather. No overlap or ambiguity.

Naming Consistency5/5

All tool names follow the verb_noun snake_case pattern consistently: find_files, get_current_datetime, get_weather.

Tool Count4/5

Three tools is small but appropriate for a 'nano' server intended as a minimal utility collection. Not too few given its scope.

Completeness3/5

The tools cover only three disparate areas with no clear domain. As a general utility set, common operations like calculations or text processing are missing, but it may be intentionally limited.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    A demonstration MCP server that provides example tools for weather queries, time retrieval, and request handling, along with advice prompts. Supports both HTTP and stdio modes for testing MCP client integrations.
    4
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal Model Context Protocol server demo that exposes tools through HTTP API, including greeting, weather lookup, and HTTP request capabilities. Demonstrates MCP server implementation with stdio communication and HTTP gateway functionality.
    7 npm
    ISC
  • F
    license
    Not graded
    quality
    D
    maintenance
    A minimal MCP server demo in Python that exposes five tools for arithmetic and a simulated long-running process.
    -