Skip to main content
Glama
hesreallyhim

MCP Observer Server

by hesreallyhim

mcp-observer-server

mcp-observer-server ist ein MCP-Server (Model Context Protocol), der Dateisystemereignisse überwacht und Echtzeitbenachrichtigungen an MCP-Clients sendet. Er fungiert als (bidirektionalere) Brücke zwischen Ihrem lokalen Dateisystem und KI-Assistenten wie Claude Inspector, sodass sie automatisch auf Dateiänderungen reagieren können.

HINWEIS: Dies ist eine Demo/ein POC eines MCP-Servers zur Dateiüberwachung, an dem ich arbeite. Ich sehe viele Fragen/Kommentare/Probleme/Diskussionen zu diesem Thema, daher möchte ich diese minimale Implementierung veröffentlichen, um meinen Ansatz zu teilen.

Kontext

Das MCP-Protokoll definiert das Konzept eines Ressourcenabonnements. Dabei kann ein Client Benachrichtigungen über Änderungen an einer Ressource anfordern und der Server kann Benachrichtigungen senden. Hier ist das Flussdiagramm:

Flussdiagramm für Ressourcenabonnements

Das Protokoll besagt, dass der Client anschließend eine Lese-Anfrage an den Server zurücksenden soll, um die Änderungen zu lesen. (All dies ist übrigens optional). Ich finde das jedoch etwas umständlich und es erfordert einen zusätzlichen Aufwand. Außerdem möchte ich, dass meine Ressourcenaktualisierungsbenachrichtigung die Änderung auch beschreibt. Glücklicherweise bietet das SDK ein meta / _meta -Feld, sodass man praktisch alles senden kann, was man möchte. So könnte ich beispielsweise die Anzahl der geänderten Zeilen, einen Diff der Änderungen oder sonst etwas senden. Das habe ich in dieser Demo nicht implementiert, ich sende derzeit nur den Zeitstempel. (Ich habe im Grunde alles vom Server entfernt, außer dem minimalen POC.) Außerdem läuft es nur über Standard-Transport, nichts Besonderes.

HINWEIS!!! Ich habe dies noch nicht mit echten MCP-Clients getestet. Meines Wissens unterstützen viele View-Clients Ressourcenabonnements, da diese ohnehin optional sind. Glücklicherweise ist Inspector jedoch ein sehr guter Client, mit dem Sie diesen Server testen können.

DEMO-ANLEITUNG:

  1. Klonen Sie das Repository.

  2. Installieren Sie die Abhängigkeiten mit uv (oder, ich nehme an, auf eine andere Weise).

  3. Führen Sie den Server mit make start (verwendet uv ) aus oder führen Sie npx @modelcontextprotocol/inspector uv run src/mcp_observer_server/server.py .

  4. Öffnen Sie den Inspector-Client und stellen Sie eine Verbindung über stdio her. Es ist keine Konfiguration erforderlich.

  5. Verwenden Sie das subscribe , um ein Verzeichnis oder eine Datei zu überwachen (alternativ können Sie „Ressourcen auflisten“ ausführen, auf eine Ressource klicken und dann auf die Schaltfläche „Abonnieren“ klicken, um sie zu abonnieren).

  6. Standardmäßig stellt der Server eine Datei namens watched.txt in src/mcp_observer_server/watched.txt bereit (die Datei hat die Erweiterung .gitignored, Sie müssen sie also erstellen). Sie können aber auch andere Dateien abonnieren. Sie können diese Datei mit dem Tool subscribe_default abonnieren.

  7. Ändern Sie die Datei watched.txt (oder die Datei, die Sie abonniert haben). Daraufhin sollte unten rechts im Inspector eine Serverbenachrichtigung angezeigt werden. Dies ist der etablierte POC.

Related MCP server: File MCP Server

DEMO-VISUALISIERUNG

  1. Starten Sie den Server und stellen Sie eine Verbindung mit Inspector her:Server starten und verbinden

  2. Listen Sie die Standardressourcen auf:Ressourcen auflisten

  3. Listen Sie die Werkzeuge auf:Tools auflisten

  4. Abonnieren Sie die Standarddatei:Standarddatei abonnieren

  5. Ändern Sie die Datei:Ändern der Datei

  6. Sehen Sie, wie die Benachrichtigung angezeigt wird: Siehe Benachrichtigung

🎉

Serverbeschreibung

Der MCP Observer Server verfolgt Datei- und Verzeichnisänderungen auf Ihrem System. MCP-Clients können diese Ereignisse abonnieren und beim Erstellen, Ändern, Löschen oder Verschieben von Dateien reagieren (die aktuelle Demo behandelt Änderungsereignisse). Dieser Server implementiert die vollständige Model Context Protocol-Spezifikation und bietet:

  • Echtzeit-Dateiüberwachung : Verwenden der Watchdog-Bibliothek zur effizienten Überwachung des Dateisystems

  • Abonnementverwaltung : Erstellen, Auflisten und Abbrechen von Überwachungsabonnements für jeden Pfad

  • Änderungsverlauf : Führt ein Protokoll der letzten Änderungen für jedes Abonnement (in der Demo weggelassen)

  • Datei- und Verzeichniszugriff : Lesen Sie Dateiinhalte und Verzeichnislisten über MCP-Ressourcen

  • Zustandsloses Design : Clients steuern, was als Reaktion auf Dateiänderungen geschieht

Hauptmerkmale

  • Abonnieren Sie Änderungen an bestimmten Dateien, Verzeichnissen oder ganzen Repositories

  • Ereignisse nach Dateimustern oder Ereignistypen filtern (in der Demo weggelassen)

  • Abfrage der letzten Änderungen, um zu sehen, welche Dateien betroffen waren (in der Demo weggelassen)

  • Zugriff auf Dateiinhalte über Ressourcenendpunkte

  • Leichtgewichtige und effiziente Implementierung mit minimalen Abhängigkeiten

  • Einfache Integration mit jedem MCP-kompatiblen Client (... der Ressourcenabonnements unterstützt)

Praktische Anwendungen

Das Hauptproblem, das ich lösen möchte, ist, dass Claude Code keine Ahnung hat, was in Ihrem Repository/Projekt passiert, es sei denn, er bearbeitet beispielsweise eine Datei und schreibt die Änderung selbst hinein. (Kennen Sie diese Benachrichtigungen – „Datei seit dem letzten Lesen geändert“?) Ein Client oder Programmierassistent, der Ihre Projektaktivitäten tatsächlich überwacht, und Sie müssen nicht jede Aufgabe an Claude delegieren, nur damit er weiß, dass sie ausgeführt wird, erscheint mir äußerst nützlich. Einige praktische Anwendungen sind:

  • Automatische Dokumentationsaktualisierungen : Halten Sie die Dokumentation mit Codeänderungen synchron – Sie aktualisieren Code, Claude wird über die Änderung benachrichtigt und prüft oder aktualisiert proaktiv die Dokumentzeichenfolgen usw.

  • Live-Codeüberprüfungen : Erhalten Sie während der Arbeit Echtzeit-Feedback zu Codeänderungen, erkennen Sie Rechtschreibfehler, Tippfehler usw. und geben Sie Ratschläge – echte Paarprogrammierung.

  • Testautomatisierung : Führen Sie Tests aus, wenn relevante Dateien geändert werden.

  • KI-Unterstützung : Aktivieren Sie KI-Tools, um automatisch auf Dateiänderungen zu reagieren.

  • Git-Commit-Automatisierung : Vergessen Sie, häufig genug zu committen? Claude kann Ihre Änderungen überwachen und Commit-Aktionen häufiger vorschlagen (oder durchführen).

Aktuelles Implementierungsdesign

Die Serverimplementierung zeichnet sich durch eine optimierte Architektur aus, bei der Einfachheit, Zuverlässigkeit und Wartbarkeit im Vordergrund stehen.

Architektur-Highlights

  1. Vereinfachte Struktur

    • Fokussierte Implementierung (~170 Zeilen Code)

    • Konsolidierte Funktionalität in einem kleinen Satz von Kernkomponenten

    • Sauberes, funktionsbasiertes Design, das das MCP SDK direkt nutzt

    • Hohe Lesbarkeit und Wartbarkeit

  2. Effizientes Zustandsmanagement

    • Einfache Wörterbuchstruktur ordnet Pfade Clientsitzungen zu

    • Verwendet ein watched Wörterbuch für die direkte Pfad-zu-Sitzungszuordnung

    • Minimale Zustandsverfolgung mit klarem Datenfluss

    • Vermeidet redundante Datenstrukturen

  3. MCP-Protokollintegration

    • Direkte Verwendung von MCP SDK-Funktionsdekoratoren

    • Saubere Handhabung von Ressourcen-URIs

    • Vereinfachte Serverinitialisierung mit entsprechender Funktionskonfiguration

    • Direktes Benachrichtigungsübermittlungssystem

  4. Ereignisverarbeitung

    • Optimierte Implementierung des Watchdog-Ereignishandlers

    • Direkter Ereignis-zu-Benachrichtigungspfad

    • Threadsichere Kommunikation über call_soon_threadsafe

    • Effiziente Ereignisfilterung

  5. Benachrichtigungssystem

    • Direkte Verwendung von MCP-Benachrichtigungsprimitiven

    • Zuverlässige Lieferung mit ordnungsgemäßer Fehlerbehandlung

    • Genaue Handhabung von UTC-Zeitstempeln

    • Saubere URI-Formatierung

Kernkomponenten

  1. Datenstruktur

    • Ein einzelnes globales Wörterbuch watched Path-Objekte Sätzen von ServerSession-Objekten zu.

    • Jeder Pfadeintrag enthält die Anzahl der Sitzungen, die für diesen Pfad abonniert sind.

  2. Tool-API

    • Zwei wesentliche Tools: subscribe und unsubscribe

    • Einfacher Pfadparameter für unkomplizierte Abonnementverwaltung

    • Saubere Fehlerbehandlung und Pfadvalidierung

  3. Ressourcenverwaltung

    • Datei-URIs werden direkt über die Ressourcenliste angezeigt

    • Pfadauflösung und -validierung

    • Lesen von Textinhalten für Dateien

  4. Ereignisverarbeitung

    • Die Watcher-Klasse erweitert FileSystemEventHandler

    • Verarbeitet geänderte Ereignisse direkt

    • Threadsicheres Versenden von Benachrichtigungen

    • Pfadrelativitätsbehandlung für verschachtelte Pfade

  5. Benachrichtigungsübermittlung

    • Erstellen und Senden von ServerBenachrichtigungen

    • Ereignismetadaten mit Zeitstempeln

    • Saubere URI-Formatierung

Die Implementierung erreicht ein gutes Gleichgewicht zwischen Funktionalität und Einfachheit, was zu einer zuverlässigen und wartbaren Codebasis führt.

Available Tools

4 tools
list_watchedA

List all currently monitored paths and their subscriber counts

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A3.6/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness2/5

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.

Parameters4/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes

TDQS

C2.8/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness2/5

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.

Parameters2/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

B3.1/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness2/5

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.

Parameters4/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYes

TDQS

C2.8/5.0
Behavior2/5

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.

Conciseness5/5

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.

Completeness2/5

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.

Parameters2/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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.

  1. 4 tool updates
    • First observedlist_watched
    • First observedsubscribe
    • First observedsubscribe_default
    • First observedunsubscribe

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation5/5

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.

Naming Consistency5/5

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.

Tool Count5/5

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.

Completeness5/5

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

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    D
    maintenance
    A 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.
    7
    1
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    A secure file server for AI assistants that provides comprehensive file operations and text manipulation with configurable access levels and multiple connection modes.
    6
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A 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.
    -