MCP Chat CLI
MCP Chat CLI
Anthropic APIを使用してMCPサーバーに接続するコマンドラインチャットインターフェースです。AnthropicのIntroduction to Model Context Protocolコースに取り組みながら構築し、カスタムツール、リソース、プロンプトで拡張しました。
これは何ですか
MCP (Model Context Protocol) は、AIモデルを外部ツールやデータソースに接続するためのオープン標準です。このプロジェクトは、その接続の両側を実装しています。ドキュメントをリソースとして公開し、読み取りや編集のためのツールを定義するFastMCPサーバーと、そのサーバーに接続してチャットインターフェース内でそれらの機能を利用可能にするクライアントです。
サーバーは以下を定義しています:
ツール — ドキュメントの読み取りと編集
リソース — すべてのドキュメントのリスト表示、またはURIによる特定のドキュメントの取得
プロンプト — ドキュメントをMarkdown形式に再フォーマット、または内容を要約
クライアントは、ツール呼び出し、リソース読み取り、プロンプト取得、コマンドの自動補完を含む、完全なMCPクライアントセッションを実装しています。
Related MCP server: MCP Chat
取り組んだこと
コースのスターターパックから始めて、両側の不足している部分を実装しました:
クライアント側の
read_resource、list_prompts、get_promptサーバー側のリソースエンドポイント (
docs://documentsおよびdocs://documents/{doc_id})利用可能なツールを使用するようにモデルに指示する2つのプロンプト (
formatおよびsummarize)
このプロジェクトを通じて具体的に理解できた主な点は、サーバー(何が利用可能かを定義する)とクライアント(それをどのように呼び出すかを知っている)の分離、そしてプロンプトとは魔法ではなく、モデルに開始コンテキストを与える構造化されたメッセージに過ぎないということです。
前提条件
Python 3.9以上
Anthropic APIキー
セットアップ
リポジトリをクローンし、プロジェクトフォルダに移動します。
仮想環境を作成し、有効化します:
uv venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # Mac/Linux依存関係をインストールします:
uv pip install -e .プロジェクトのルートに
.envファイルを作成します:
ANTHROPIC_API_KEY="your-key-here"アプリを実行します:
uv run main.py使用方法
メッセージを入力してチャットします。クエリにドキュメントを含めるには @doc_id を、プロンプトをトリガーするには /command を使用します。Tabキーで利用可能なコマンドを自動補完できます。
> Tell me about @deposition.md
> /summarize report.pdf
> /format plan.md独自のドキュメントを追加するには、mcp_server.py 内の docs 辞書を編集してください。
サーバーの直接テスト
mcp dev mcp_server.pyこれによりブラウザでMCP Inspectorが開き、チャットインターフェースなしでツール、リソース、プロンプトをテストできます。
プロジェクト構造
mcp_chat_cli/
├── main.py # entrypoint
├── mcp_server.py # FastMCP server — tools, resources, prompts
├── mcp_client.py # MCP client session wrapper
├── core/
│ ├── chat.py # chat loop logic
│ ├── claude.py # Anthropic API integration
│ ├── cli.py # CLI setup and input handling
│ ├── cli_chat.py # connects CLI and chat
│ └── tools.py # tool call handling
├── .env # API key (not committed)
└── pyproject.toml # dependenciesAvailable Tools
2 toolsedit_documentA
Edit a document by replacing a string in the documents content with a new string.
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | Id of the document that will be edited | |
| old_str | Yes | The text to replace. Must match exactly, including whitespace. | |
| new_str | Yes | The new text to insert in place of the old text. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description must disclose behavioral traits. It only states 'replacing a string' without indicating whether it replaces all occurrences, behavior on missing string, or side effects like auto-save. Missing important mutation details.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence that is concise and front-loaded with the essential action and resource. No wasted words.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple edit tool with fully documented parameters, the description is adequate but lacks details on error handling (e.g., what if old_str not found) and whether it replaces all occurrences or just the first.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, and the description adds value by clarifying that old_str must match exactly including whitespace. This goes beyond the schema's basic descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action (edit), resource (document), and method (string replacement). It effectively distinguishes from the sibling tool 'read_doc_contents' which is read-only.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description does not explicitly state when to use this tool vs alternatives. While the sibling tool name implies a read vs. edit distinction, no further guidance is provided on prerequisites or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
read_doc_contentsA
Read the contents of a document and return it as a string.
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | Id of the document to read |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden of behavioral disclosure. It does state the output behavior ('return it as a string'), but does not mention error handling, permissions, or what happens when the document does not exist. For a simple read operation, this is adequate but not rich.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence with no wasted words. It efficiently conveys both the operation and the return format.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
This is a simple tool with one parameter, full schema coverage, and no output schema. The description is largely complete for a read operation, especially since it explicitly states the return type. It could be slightly stronger with error or permission context, but nothing essential is missing for basic invocation.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema already fully documents the only parameter, doc_id, as 'Id of the document to read', so schema coverage is 100%. The description adds no additional parameter meaning beyond the schema, matching the baseline score.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb and resource: 'Read the contents of a document' and explicitly notes the return type as a string. This clearly distinguishes it from the sibling 'edit_document', which implies modification rather than reading.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The verb 'Read' establishes a clear context for when this tool is appropriate, and its contrast with 'edit_document' implies read-only usage. However, it does not explicitly state when not to use it or name the alternative.
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.
2 tool updates
v0.1.0- First observed
edit_document - First observed
read_doc_contents
TDQS
Scored across 2 tools
The two tools have completely distinct purposes: one reads document contents, the other edits by replacing text. There is no functional overlap.
Both tool names follow the verb_noun pattern (edit_document, read_doc_contents), with consistent snake_case and clear action-object structure.
With only two tools, the server feels thin for a document utility, though it could be a minimal implementation. It falls into the borderline category (1-2 tools).
The server lacks basic CRUD operations like create and delete documents. While read and edit are provided, agents cannot create new documents or remove them, which are significant gaps.
Maintenance
Related MCP Connectors
Search your AI chat history (ChatGPT, Claude, Codex) from any MCP client. Remote, private, read-only
Build your own tools from chat: design, test and host them on a shareable MCP server URL.
1Augments MCP Server - A comprehensive framework documentation provider for Claude Code
- QuallaaOAuthcom.quallaa
Talk to your public-facing AI from any MCP client — Claude, ChatGPT, Cursor, Cline, Windsurf.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA command-line interface application for interactive chat with AI models via the Anthropic API. It supports document retrieval, command-based prompts, and extensible tool integrations through the MCP architecture.-
- FlicenseNot gradedqualityDmaintenanceA command-line interface application that enables interactive chat with AI models via the Anthropic API, supporting document retrieval and command-based prompts through the MCP architecture.-
- FlicenseAqualityCmaintenanceEnables interactive chat with a local LLM using MCP architecture for document management, including tools to read, edit, and format documents.2-
- FlicenseNot gradedqualityDmaintenanceAn MCP server that provides document management capabilities including reading, editing, and summarizing documents through a CLI chat interface powered by Claude AI.-