MCP Observer Server
mcp-オブザーバーサーバー
mcp-observer-serverファイルシステムのイベントを監視し、MCPクライアントにリアルタイム通知を提供するMCP(Model Context Protocol)サーバーです。これは、ローカルファイルシステムとAIアシスタント(例えば、クロードインスペクターにより、ファイルの変更に自動的に対応できるようになります。
**注:**これは私が現在開発中のファイル監視MCPサーバーのデモ/POCです。この件に関して多くの質問、コメント、問題、議論をいただいているため、私のアプローチを共有するために、この最小限の実装を投稿することにしました。
コンテクスト
MCPプロトコルはリソースサブスクリプションの概念を定義します。クライアントはリソースへの変更があった場合に通知を要求でき、サーバーは通知を送信するかどうかを選択できます。フロー図を以下に示します。

プロトコルでは、クライアントは変更内容を読み取るためにサーバーに読み取りリクエストを返すように指定されています(ちなみに、これらはすべてオプションです)。しかし、これは少し面倒で、余分なやり取りが必要になるため、リソース更新通知にも変更内容を記述してもらいたいと考えています。幸い、SDKにはmeta / _metaフィールドが用意されているので、ほぼ何でも送信できます。変更された行数や変更点の差分など、送信したい情報も送信できます。このデモではそれを実装しておらず、今はタイムスタンプのみを送信しています(最小限のPOCを除いて、サーバーからすべて削除しました)。また、stdioトランスポートで実行されているだけで、特別な処理は施していません。
注意!まだ「本物の」MCPクライアントでテストしていません。私の理解では、リソースサブスクリプションはオプションなので、ほとんどのビュークライアントが実際にサポートしているはずです。しかし、幸いなことにInspectorは非常に優れたクライアントなので、このサーバーをテストするのに使用できます。
デモの手順:
リポジトリをクローンします。
uv(または、他の方法) を使用して依存関係をインストールします。make start(uvを使用) を使用してサーバーを実行するか、npx @modelcontextprotocol/inspector uv run src/mcp_observer_server/server.py実行します。Inspector クライアントを開き、stdio を使用して接続します。構成は必要ありません。
subscribeツールを使用して、ディレクトリまたはファイルを監視します (または、「リソースの一覧表示」を実行し、リソースをクリックして、「サブスクライブ」ボタンをクリックしてサブスクライブすることもできます)。デフォルトでは、サーバーは
src/mcp_observer_server/watched.txtにwatched.txtというファイルを公開します(このファイルは .gitignored なので、作成する必要があります)。ただし、他のファイルも購読できます。このファイルはsubscribe_defaultツールを使って購読できます。watched.txtファイル(またはサブスクライブしたファイル)を変更すると、インスペクターの右下パネルにサーバー通知が表示されます。これで POC が確立されました。
Related MCP server: File MCP Server
デモの視覚化
サーバーを起動し、Inspector で接続します。

デフォルトのリソースを一覧表示します。

ツールをリストします:

デフォルトのファイルをサブスクライブします:

ファイルを変更します:

通知が表示されます:

🎉
サーバーの説明
MCP Observer Serverはシステム上のファイルとディレクトリの変更を追跡し、MCPクライアントがこれらのイベントをサブスクライブして、ファイルの作成、変更、削除、または移動時にアクションを実行できるようにします(現在のデモでは変更イベントを処理します)。このサーバーは、モデルコンテキストプロトコル仕様を完全に実装しており、以下を提供します。
リアルタイムファイル監視: Watchdogライブラリを使用した効率的なファイルシステム監視
サブスクリプション管理: 任意のパスの監視サブスクリプションを作成、一覧表示、キャンセルします
変更履歴: 各サブスクリプションの最近の変更のログを保持します (デモでは省略)
ファイルとディレクトリのアクセス: MCP リソースを通じてファイルの内容とディレクトリの一覧を読み取ります
ステートレス設計: クライアントはファイルの変更に応じて何が起こるかを制御します
主な特徴
特定のファイル、ディレクトリ、またはリポジトリ全体の変更を購読する
ファイルパターンまたはイベントタイプでイベントをフィルタリングする(デモでは省略)
最近の変更を照会して、影響を受けたファイルを確認します(デモでは省略)
リソースエンドポイント経由でファイルの内容にアクセスする
最小限の依存関係で軽量かつ効率的な実装
MCP 互換クライアント(リソース サブスクリプションをサポートするもの)とのシンプルな統合
実用的な応用
私が解決しようとしている主な問題点は、例えばClaude Codeがファイルにアクセスして変更内容をそのファイルに書き込まない限り、リポジトリ/プロジェクトで何が起こっているのか全く把握できないことです。(「前回の読み取り以降にファイルが変更されました」という通知をご存知ですか?)プロジェクトで実際に何をしているかを監視してくれるクライアントやコーディングアシスタントがあれば、Claudeにタスクの発生を知らせるためだけにすべてのタスクを委任する必要がなくなり、非常に便利に思えます。具体的な応用例を以下に示します。
自動化されたドキュメント更新: コードの変更とドキュメントの同期を維持します。コードを更新すると、Claude に変更が通知され、ドキュメント文字列などが積極的にチェックまたは更新されます。
ライブ コード レビュー: 作業中にコードの変更に関するフィードバックをリアルタイムで取得し、スペル エラーや入力エラーなどを検出してアドバイスを提供し、真のペア プログラミングを実現します。
テストの自動化: 関連するファイルが変更されたときにテストを実行します。
AI アシスタンス: AI ツールを有効にして、ファイルの変更に自動的に応答します。
Git コミット自動化: コミットを頻繁に忘れていませんか? Claude は変更を監視し、より頻繁にコミットアクションを提案 (または実行) します。
現在の実装設計
サーバーの実装は、シンプルさ、信頼性、保守性を重視した合理化されたアーキテクチャを特徴としています。
建築のハイライト
簡素化された構造
集中的な実装(コード約170行)
機能を少数のコアコンポーネントに統合
MCP SDKを直接活用するクリーンな関数ベースの設計
高い可読性と保守性
効率的な状態管理
シンプルな辞書構造がパスをクライアントセッションにマッピングします
watched辞書を使用して、パスからセッションへの直接マッピングを行う明確なデータフローによる最小限の状態追跡
冗長なデータ構造を回避する
MCPプロトコル統合
MCP SDK 関数デコレータの直接使用
クリーンなリソースURI処理
適切な機能構成による簡素化されたサーバー初期化
直接通知配信システム
イベント処理
合理化されたウォッチドッグイベントハンドラーの実装
イベントから通知への直接パス
call_soon_threadsafeによるスレッドセーフな通信効率的なイベントフィルタリング
通知システム
MCP通知プリミティブの直接使用
適切なエラー処理による信頼性の高い配信
正確なUTCタイムスタンプ処理
クリーンなURIフォーマット
コアコンポーネント
データ構造
watched対象の単一のグローバル辞書は、Path オブジェクトを ServerSession オブジェクトのセットにマッピングします。各パスエントリには、そのパスにサブスクライブされているセッションのセットが含まれます。
ツールAPI
2つの必須ツール:
subscribeとunsubscribe簡単なサブスクリプション管理のためのシンプルなパスパラメータ
クリーンなエラー処理とパス検証
リソースハンドリング
リソースリストを通じて直接公開されるファイル URI
パス解決と検証
ファイルのテキストコンテンツの読み取り
イベント処理
WatcherクラスはFileSystemEventHandlerを拡張します
変更されたイベントを直接処理します
スレッドセーフな通知ディスパッチ
ネストされたパスのパス相対処理
通知配信
ServerNotificationの作成と送信
タイムスタンプ付きイベントメタデータ
クリーンなURIフォーマット
この実装により、機能性とシンプルさのバランスが適切に保たれ、信頼性が高く保守しやすいコードベースが実現します。
Available Tools
4 toolslist_watchedA
List all currently monitored paths and their subscriber counts
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It indicates a read operation ('List') but doesn't specify whether this requires authentication, how data is returned (e.g., format, pagination), or any rate limits. The description is minimal and lacks essential behavioral context for a tool that likely interacts with subscription systems.
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, efficient sentence that front-loads the core purpose without any wasted words. It directly communicates the tool's function in a clear and structured manner, making it easy to understand at a glance.
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?
Given the tool's complexity (likely low, but involves subscription monitoring), no annotations, and no output schema, the description is insufficient. It doesn't explain what the output looks like (e.g., list format, data structure), potential errors, or operational constraints, leaving significant gaps for an AI agent to use it effectively.
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 tool has 0 parameters with 100% schema description coverage, so the schema fully documents the absence of inputs. The description doesn't need to compensate for any parameter gaps, and it appropriately doesn't mention parameters, making it complete in this regard. A baseline of 4 is appropriate for zero-parameter tools.
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 specific action ('List all') and resource ('currently monitored paths and their subscriber counts'), distinguishing it from sibling tools like subscribe/unsubscribe which perform different operations. It precisely defines what the tool does without being vague or tautological.
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 implies usage context by specifying 'currently monitored paths,' suggesting this tool is for viewing existing subscriptions rather than modifying them. However, it doesn't explicitly state when to use this versus alternatives or provide any exclusion criteria, leaving some ambiguity about its specific application scenarios.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
subscribeC
Subscribe to changes on a file or directory
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Subscribe to changes' implies a monitoring/notification function, it doesn't describe what kind of changes trigger notifications, how notifications are delivered, whether this requires specific permissions, rate limits, or what happens when multiple subscriptions exist. This leaves significant behavioral gaps for a tool that likely establishes ongoing monitoring.
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, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized for a tool with one parameter and gets straight to the point with zero wasted verbiage.
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 subscription tool with no annotations, no output schema, and minimal parameter documentation, the description is inadequate. It doesn't explain what 'subscribing' entails operationally, what format notifications take, how to manage subscriptions, or what the tool returns. Given the complexity of establishing monitoring and the complete lack of structured documentation, this description leaves too many questions unanswered.
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?
With 0% schema description coverage for the single 'path' parameter, the description provides no additional semantic information about what the path represents, its format, or constraints. The description mentions 'file or directory' which gives some context for the path parameter, but this is minimal compensation for the complete lack of schema documentation.
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 ('Subscribe to changes') and target resource ('on a file or directory'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'subscribe_default', which appears to be a related subscription tool, so it doesn't fully differentiate from alternatives.
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 provides no guidance on when to use this tool versus alternatives like 'subscribe_default' or 'list_watched'. It doesn't mention prerequisites, exclusions, or contextual factors that would help an agent choose between subscription-related tools.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
subscribe_defaultB
Subscribe to the default watched.txt file for development
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('subscribe') but doesn't explain what subscription entails (e.g., real-time updates, notifications, persistence), permissions required, side effects, or error conditions. This leaves significant gaps for a mutation-like operation.
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, efficient sentence with no wasted words. It front-loads the core action and target, making it easy to parse quickly. Every element ('subscribe', 'default', 'watched.txt file', 'development') contributes meaning without redundancy.
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?
Given the tool has no parameters (simplifying input) but no annotations or output schema, the description is incomplete. It lacks details on behavior, return values, error handling, and differentiation from siblings like 'subscribe'. For a subscription tool with mutation implications, this leaves too many unknowns for effective agent use.
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 tool has 0 parameters, and schema description coverage is 100% (empty schema). The description doesn't need to add parameter details, and it appropriately avoids discussing nonexistent inputs. A baseline of 4 is applied since no parameters exist to document.
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 ('subscribe') and target resource ('default watched.txt file for development'), making the purpose understandable. It doesn't explicitly distinguish from sibling tools like 'subscribe' (which likely allows custom targets) or 'list_watched'/'unsubscribe', but the specificity of 'default' provides some implicit differentiation.
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?
No explicit guidance is provided on when to use this tool versus alternatives like 'subscribe' (for non-default files) or 'list_watched' (for viewing subscriptions). The description implies it's for development purposes, but doesn't clarify prerequisites, exclusions, or specific use cases compared to siblings.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
unsubscribeC
Unsubscribe from changes on a file or directory
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Unsubscribe from changes') but doesn't explain what 'changes' refers to, whether this operation is reversible, what permissions are required, or what happens after unsubscribing (e.g., notifications stop). For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.
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, efficient sentence with zero waste—it directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.
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?
Given the tool's complexity (a mutation operation with no annotations, no output schema, and low schema coverage), the description is incomplete. It lacks details on behavioral traits, parameter usage, output expectations, and differentiation from siblings, making it inadequate for informed tool selection and 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 input schema has 1 parameter with 0% description coverage, so the schema provides no semantic information. The description mentions 'a file or directory' but doesn't clarify what the 'path' parameter represents (e.g., format, examples, or constraints). It adds minimal value beyond the schema's structural definition.
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 ('Unsubscribe from changes') and the target resource ('on a file or directory'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from its sibling 'subscribe' or 'subscribe_default', which would require mentioning what makes 'unsubscribe' different from those subscription tools.
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 provides no guidance on when to use this tool versus alternatives like 'list_watched' or when not to use it. There's no mention of prerequisites (e.g., needing an existing subscription) or contextual cues for selection among sibling tools, leaving usage decisions ambiguous.
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.
4 tool updates
- First observed
list_watched - First observed
subscribe - First observed
subscribe_default - First observed
unsubscribe
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose with no overlap: list_watched for viewing current subscriptions, subscribe for adding new ones, subscribe_default for a specific default case, and unsubscribe for removal. The descriptions reinforce these distinct roles, making misselection unlikely.
All tools follow a consistent verb_noun pattern (list_watched, subscribe, subscribe_default, unsubscribe) with clear, action-oriented names. The naming is uniform and predictable, enhancing usability.
With 4 tools, this server is well-scoped for its purpose of monitoring file/directory changes. Each tool serves a necessary function in the subscription lifecycle, and the count is neither too sparse nor bloated.
The tool set provides complete coverage for the domain of file/directory monitoring: list (read), subscribe (create), unsubscribe (delete), and a specialized subscribe_default for convenience. There are no obvious gaps, supporting full agent workflows.
Maintenance
Related MCP Connectors
Shared rooms for existing AI assistants, with messages, files and private memory vaults.
Driflyte MCP server which lets AI assistants query topic-specific knowledge from web and GitHub.
- ZapierOAuthcom.zapier
Hosted MCP server connecting AI assistants to 9,000+ apps and 40,000+ actions via Zapier.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseAqualityFmaintenanceA Model Context Protocol server that provides AI agents with secure access to local filesystem operations, enabling reading, writing, and managing files through a standardized interface.10181 npm53Apache 2.0
- FlicenseAqualityDmaintenanceA Model Context Protocol (MCP) server that enables AI assistants to perform comprehensive file operations including finding, reading, writing, editing, searching, moving, and copying files with security validations.71-
- AlicenseNot gradedqualityCmaintenanceA secure file server for AI assistants that provides comprehensive file operations and text manipulation with configurable access levels and multiple connection modes.6MIT
- FlicenseNot gradedqualityDmaintenanceA secure, sandboxed file system server that enables reading, writing, searching, and managing files through MCP-compatible AI clients with path traversal protection and size limits.-