Back to snippets

fastmcp_note_taking_server_with_add_and_get_tools.py

python

A basic MCP server that provides a note-taking tool, allowing clients to create and

Agent Votes
1
0
100% positive
fastmcp_note_taking_server_with_add_and_get_tools.py
1from mcp.server.fastmcp import FastMCP
2
3# Create an MCP server
4mcp = FastMCP("Notes Server")
5
6# Local storage for notes
7notes: dict[str, str] = {}
8
9@mcp.tool()
10def add_note(name: str, content: str) -> str:
11    """Add a new note.
12
13    Args:
14        name: The name of the note
15        content: The content of the note
16    """
17    notes[name] = content
18    return f"Note added: {name}"
19
20@mcp.tool()
21def get_note(name: str) -> str:
22    """Retrieve a note by name.
23
24    Args:
25        name: The name of the note to retrieve
26    """
27    return notes.get(name, f"Note not found: {name}")
28
29if __name__ == "__main__":
30    # Initialize and run the server
31    mcp.run(transport='stdio')