fastmcp logo

Fastmcp

by punkpeye

38 forks
531 stars
Free

What is fastmcp

fastmcp is a TypeScript framework designed by Punkpeye for building MCP (Model Context Protocol) servers. These servers facilitate handling client sessions and allow AI systems to securely interact with various data sources and tools. As a part of the MCP ecosystem, fastmcp provides a standardized way for AI assistants to access external data, tools, and prompts through a client-server architecture. This enables AI systems to perform tasks like accessing real-time information, managing data, and executing functions.

How to Use fastmcp

To get started with fastmcp, you need to install the package using npm. Once installed, you can set up a server by importing FastMCP and defining your tools and resources. Here’s a brief outline of the steps to set up a basic server:

  1. Installation:

    npm install fastmcp
    
  2. Server Setup:

    import { FastMCP } from "fastmcp";
    import { z } from "zod";
    
    const server = new FastMCP({
      name: "My Server",
      version: "1.0.0",
    });
    
    server.addTool({
      name: "add",
      description: "Add two numbers",
      parameters: z.object({
        a: z.number(),
        b: z.number(),
      }),
      execute: async (args) => {
        return String(args.a + args.b);
      },
    });
    
    server.start({
      transportType: "stdio",
    });
    
  3. Testing: You can test your server using the command line interface. This involves running the server and using MCP CLI for testing and debugging.

  4. SSE Support: If needed, you can enable Server-Sent Events (SSE) to handle real-time data streaming.

Key Features of fastmcp

  • Tool Definition: Easily define tools that expose executable functions to clients. Tools can return strings, images, or lists.

  • Resource Management: Manage resources like files and logs, making them accessible to clients via unique URIs.

  • Prompt Templates: Create reusable prompt templates that standardize interactions with AI systems.

  • Authentication: Securely authenticate clients with custom authentication functions to control access.

  • Session Management: Manage client sessions seamlessly, providing a robust framework for interaction.

  • Typed Server Events: Listen to server events such as client connections and disconnections, enabling responsive server behavior.

  • Error Handling: Utilize structured error handling to manage user-facing errors and operational logs.

  • Progress Notifications: Report task progress through the server to provide real-time feedback to clients.

  • CORS Support: Cross-Origin Resource Sharing (CORS) is enabled by default, ensuring flexible client-server interactions.

  • CLI Tools: Use the command line interface for testing and debugging your server, enhancing the development experience.

fastmcp provides a comprehensive toolkit for developers looking to build robust and secure MCP servers. Its features facilitate efficient server setup, management, and interaction with AI clients, making it a powerful choice for integrating AI capabilities into various applications.

How to Use

To use the fastmcp, follow these steps:

  1. Visit https://github.com/punkpeye/fastmcp
  2. Follow the setup instructions to create an account (if required)
  3. Connect the MCP server to your Claude Desktop application
  4. Start using fastmcp capabilities within your Claude conversations

Additional Information

Created

December 27, 2024

Company

punkpeye

Start building your own MCP Server

Interested in creating your own MCP Server? Check out the official documentation and resources.

Learn More