Skip to main content
Glama
mcp-notes-server

mcp-notes-server

by ByteTrooper
README.md
# mcp-notes-server

A small notes server that speaks the [Model Context Protocol](https://modelcontextprotocol.io) over
stdio, written with the Python standard library only. An MCP client can let an LLM **save, list,
search and delete notes** through tool calls. Notes live in a single JSON file.

The point of the repo is to show what an MCP tool server actually does on the wire, with no SDK
in the way: about 150 lines you can read in one sitting.

## Tools

| tool | arguments | what it does |
|---|---|---|
| `add_note` | `text` (required), `title`, `tags[]` | saves a note and returns its id |
| `list_notes` | `limit` (default 20) | newest first |
| `search_notes` | `query` | notes containing every word of the query, in title, text or tags |
| `delete_note` | `id` | removes a note |

Bad arguments come back as a tool result with `isError: true`, so the model can see the error and
retry. Protocol-level problems (unknown method, malformed JSON) use JSON-RPC error codes.

## What is implemented

- `initialize`, `ping`, `tools/list`, `tools/call`
- notifications (such as `notifications/initialized`) are accepted and never answered
- newline-delimited JSON-RPC 2.0 on stdin/stdout, logs to stderr only
- atomic writes (temp file then rename), so a crash never leaves a half-written notes file
- Unicode notes (Telugu, Hindi, and so on) are stored as-is

Not implemented: resources, prompts, sampling, progress or cancellation. It only covers tools.

## Run it

```bash
python -m pytest -q          # 7 tests, each talks to the real server process over stdio
NOTES_FILE=./notes.json python mcp_notes_server.py
```

Then type one JSON message per line:

```
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"cli","version":"0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"add_note","arguments":{"text":"Try LangGraph checkpoints","tags":["ideas"]}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_notes","arguments":{"query":"langgraph"}}}
```

To register it with an MCP client, point the client's server config at:

```json
{ "command": "python3", "args": ["/path/to/mcp_notes_server.py"], "env": { "NOTES_FILE": "/path/to/notes.json" } }
```

## Status

The tests use a small client that follows the protocol's stdio framing. I have not verified the
server against every MCP client, so if one rejects the handshake, please open an issue with its log.

## License

MIT