Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Core Types for Third-Party Development #10

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

bunasQ
Copy link
Contributor

@bunasQ bunasQ commented Feb 19, 2025

Motivation

As the FastMCP framework grows in adoption, third-party developers need access to core types to build their own abstractions and extensions. Currently, many essential types are internal to the framework, making it challenging to create type-safe custom implementations and abstractions like base classes for tools, resources, and prompts.

Benefits

  1. Enhanced Developer Experience

    • Better TypeScript support with proper type inference
    • Reduced need to redefine types in third-party code
    • Improved IDE support with accurate type information
  2. Safer Third-Party Development

    • Type-safe implementations of custom abstractions
    • Clearer API contract through explicit type exports
    • Reduced potential for runtime errors through compile-time type checking
  3. Framework Extensibility

    • Easier creation of reusable base classes and utilities
    • Better support for building custom tool, resource, and prompt abstractions
    • Simplified development of framework plugins and extensions

Example Use Case

import { FastMCP, Context, ToolParameters, ContentResult } from "fastmcp";
import { z } from "zod";

export abstract class BaseTool {
  abstract name: string;
  abstract description: string;
  abstract params: ToolParameters;

  register(server: FastMCP) {
    server.addTool({
      name: this.name,
      description: this.description,
      parameters: this.params,
      execute: this.execute.bind(this),
    });
  }

  abstract execute(
    args: z.infer<typeof this.params>,
    context: Context
  ): Promise<ContentResult>;
}

@bunasQ bunasQ force-pushed the feature/export-types branch from 5b10d94 to 7a0a563 Compare February 19, 2025 05:32
@punkpeye punkpeye merged commit 3e0d604 into punkpeye:main Feb 20, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants