MO

ModelFetch MCP Server SDK for TypeScript

Build and deploy runtime-agnostic MCP server apps with the ModelFetch TypeScript SDK, running anywhere TypeScript/JavaScript is supported.

Overview

ModelFetch MCP Server SDK for TypeScript is a developer-focused toolkit for building Model Context Protocol (MCP) server applications in TypeScript and JavaScript. It provides a lightweight, runtime-agnostic layer that helps you expose model-backed capabilities (models, tools, and workflows) over a standard MCP-compatible interface so your apps can run on Node.js, Deno, Cloudflare Workers, or any environment that supports TypeScript/JavaScript.

The SDK is useful when you want a consistent server-side surface for multiple model providers, shared tooling (e.g., retrieval tools, sanitizers, or toolkits), or when you need to deploy model-driven endpoints across different runtimes without rewriting request handling logic. It includes TypeScript types, request/response adapters, and helper primitives to register models and tools and to handle streaming and non-streaming invocations uniformly.

Features

  • Runtime-agnostic MCP server primitives (Node, Deno, Workers, and other JS runtimes)
  • TypeScript-first SDK with type definitions for safe developer experience
  • Simple adapters to integrate with Express, Fastify, or native fetch handlers
  • Support for registering models and tools and exposing them via MCP
  • Consistent handling for streaming and non-streaming model outputs
  • Environment-friendly configuration (works well with serverless and edge functions)
  • Example apps and templates to bootstrap MCP services quickly

Installation / Configuration

Install the package from npm (replace with your package registry if required):

# npm
npm install modelfetch

# yarn
yarn add modelfetch

# pnpm
pnpm add modelfetch

Basic environment variables used by typical deployments:

  • PORT — HTTP port to listen on (Node)
  • MF_API_KEY — API key for any external model provider you wire up
  • MF_BACKEND — optional backend selector (e.g., “openai”, “local”, “custom”)

Example .env:

PORT=3000
MF_API_KEY=sk-xxxxxx
MF_BACKEND=openai

TypeScript configuration (tsconfig.json) should target a modern ES runtime for best compatibility:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  }
}

Quick Start Examples

Minimal Node + Express example (TypeScript):

import express from "express";
import { createMCPHandler } from "modelfetch"; // handler adapter from SDK

// register your models/tools via SDK exports (pseudo-code)
import { registerModel, registerTool } from "modelfetch";

registerModel("default", { provider: "openai", model: "gpt-4o" });
registerTool("search", async (query) => {
  // custom retrieval logic
  return [{ id: 1, text: "Result" }];
});

const app = express();
app.use(express.json());

// mount the MCP handler at /mcp
app.post("/mcp", createMCPHandler());

const port = process.env.PORT ?? 3000;
app.listen(port, () => {
  console.log(`MCP server listening on http://localhost:${port}`);
});

Cloudflare Worker (Edge) example:

import { createMCPHandler } from "modelfetch";

const handler = createMCPHandler(); // returns a function that accepts Request

addEventListener("fetch", (event) => {
  event.respondWith(handler(event.request));
});

The SDK supplies adapters so the same registered models/tools are reachable regardless of how the HTTP surface is mounted.

Available Resources

  • GitHub repository: https://github.com/phuctm97/modelfetch/ — source code, issues, and examples
  • Examples folder (in repo) — starter projects for Node, Deno, and Worker deployments
  • TypeScript types — included in the package for autocompletion and compile-time checks
  • API reference — check the repository README or docs directory for the latest export list and adapters
  • Issues/Discussions — use the GitHub repo to report bugs or request features

Use Cases

  • Unified model gateway: expose a single MCP-compatible endpoint that routes requests to multiple model providers depending on configuration or tenant.
  • Serverless model proxies: deploy small MCP services as serverless functions or edge workers for low-latency inference or middleware logic (e.g., prompt sanitization, observability).
  • Tool orchestration: register retrieval tools, search connectors, or database lookup functions that models can call during generation, without coupling to a single runtime.
  • Local development and testing: run a local MCP server that simulates production model responses, record/playback model interactions, or run integration tests against a stable MCP surface.
  • Multi-runtime deployments: write your handler logic once (register models, tools, and workflows) and deploy it to Node, edge, or serverless runtimes with minimal changes.

Tips for Getting Started

  • Start with the repository examples to see runtime-specific adapters in action.
  • Keep model registration centralized (e.g., a single bootstrap file) so the same configuration applies across runtimes.
  • Use environment variables and secrets managers to avoid embedding API keys in source code.
  • Leverage TypeScript types exported by the SDK to reduce runtime errors when wiring models and tools.

This SDK is intended for developers who want a consistent, portable MCP surface for their model-driven services. Refer to the repository examples and API docs for the concrete exported functions and adapter helpers.