npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@flipdish/mcp-sdk

v0.3.0

Published

Define a service's MCP tools once: serve them at the service's MCP route and emit the manifest the flipdish-mcp gateway reads

Readme

@flipdish/mcp-sdk

Define a service's MCP tools once. The SDK serves them at the service's MCP route and emits the <service>.mcp-manifest.json the flipdish-mcp gateway (mcp.flipdish.com) reads to advertise them and route their calls (EDR-96). Both come from the same definitions, so the endpoint and the manifest cannot drift.

Installation

pnpm add @flipdish/mcp-sdk

The package bundles its own zod 4 and MCP server SDK, and no zod type is part of its API, so it works alongside a service still on zod 3. @types/aws-lambda is an optional peer, needed for the types of @flipdish/mcp-sdk/aws-lambda; aws-cdk-lib and constructs are optional peers, needed only for @flipdish/mcp-sdk/cdk.

Define the tools

import { defineMcpService, input, McpToolError } from '@flipdish/mcp-sdk';

export const reportMcp = defineMcpService({
  service: 'report-builder',
  team: 'reporting',
  version: '1.0.0',
  routeTemplate: '/mcp/orgs/{orgId}/brands/{brandId}',
  timeoutMs: 28_000,
  featureFlag: 'backend_reporting_reportBuilderMcp',
  // Built once per tools/call, from the route params and headers; pass `signal` to upstream calls.
  context: (request) => ({ tenant: { orgId: request.orgId, brandId: request.brandId }, translate: translator(request.acceptLanguage) }),
  // Model-visible text for an expected error; undefined logs it and answers a generic message.
  mapError: (error, call) => (error instanceof ReportNotFoundError ? call.context.translate('Report_not_found') : undefined),
  // Optional: wraps every call, e.g. in a tracing span.
  aroundToolCall: (call, run) => tracer.trace(`report-mcp.${call.tool}`, run),
  tools: (tool) => [
    tool({
      name: 'get_report',
      description: 'Shows one saved report. orgId comes from get_orgs, brandId from get_brands, reportId from list_reports.',
      readOnly: true,
      input: {
        reportId: input.string({ description: 'The ReportId from list_reports (e.g. "weekly-sales").', minLength: 1, maxLength: 100 }),
        scope: input.enum(['private', 'brand', 'org'], { description: 'Who can see it: "private", "brand" or "org".' }).optional(),
      },
      handler: async ({ reportId }, { context, request, signal }) => formatReport(await getReport(reportId, context.tenant, signal)),
    }),
  ],
});
  • Inputs are flat scalars: input.string, input.enum, input.number, input.integer and input.boolean, each optionally .optional(). Each one is the JSON Schema property the manifest advertises, and tools/call validates against that same schema, converted the way the gateway converts it. Plain-decimal text for a number, "true"/"false" for a boolean and a plain number for a string are accepted; "", "1e3" and "yes" are not. trim: true trims a string before its length is checked.
  • orgId and brandId come from the route, never from input (a type error and a runtime error). request.brandId is a string when the route template has {brandId}. If a single service mixes org-scoped and brand-scoped tools, set routeTemplate on the tools that need a different route so the service still publishes one manifest.
  • request.token is the caller's Flipdish token (the FD-Authorization header the gateway sends, else the Authorization bearer), for calls made on their behalf. Never log it.
  • Results: return a string, or { content: [{ type: 'text', text }] }; json(value) builds indented JSON text. Throw McpToolError('…') for a failure the model may read. Anything else is logged and answered with a generic message, which for a write tool tells the model the change may have saved.
  • Invalid arguments come back as a tool error (isError: true) naming each argument, the problem, and the argument's description, so the model can retry.
  • The definitions are checked with the gateway's own validator when defineMcpService runs: a snake_case name, no duplicate, no legacy term (store ID, app ID, white label, …) in a name, title, description, input or the instructions. A result, or an McpToolError or mapError message, carrying a legacy identifier (storeId, appId, …) is logged and replaced with the generic failure, since the gateway would fail that call anyway. Ordinary words ("franchisee") pass, as at the gateway, since they can be user-written text.

Serve the route

On an API Gateway HTTP API (payload 2.0):

import { toApiGatewayHandler } from '@flipdish/mcp-sdk/aws-lambda';

export const handler = toApiGatewayHandler(reportMcp);

Route POST <routeTemplate> to it behind the service's authorizer: the SDK checks no permission. Each handler's signal aborts 3 seconds (responseReserveMs) before the Lambda times out, and the call answers a "ran out of time" tool error then, even if the handler ignores the signal (pass it on to upstream calls so the work stops too). Elsewhere, reportMcp.fetch(request) serves a Fetch API Request; the route params are read from the end of the URL path.

The endpoint is stateless Streamable HTTP with JSON responses, which is what the gateway sends: a tools/call with no initialize first. Direct MCP clients on the 2025 or 2026-07-28 protocol work too.

Publish the manifest

Pass the service's public base URLs for the shared stages. mcpManifestTarget picks the gateway bucket, the base URL and allowExecuteApi for the deploy stage. An ephemeral stage uploads only when both MCP_MANIFEST_BUCKET and a literal MCP_MANIFEST_BASE_URL are set.

import { McpManifestDeployment, mcpManifestTarget } from '@flipdish/mcp-sdk/cdk';

const target = mcpManifestTarget({
  stage: app.stage,
  baseUrls: {
    production: 'https://api.flipdish.co/report-builder',
    'prod-staging': 'https://api-prod-staging.portal.flipdishdev.com/report-builder',
  },
});

if (target) {
  new McpManifestDeployment(stack, 'McpManifest', {
    bucketName: target.bucketName,
    manifest: reportMcp.manifest({ baseUrl: target.baseUrl, allowExecuteApi: target.allowExecuteApi }),
    serviceEndpoint: api,
  });
}

manifest() validates with @flipdish/mcp-manifest and throws McpManifestError listing every issue. allowExecuteApi is false on production only. The base URL must be a literal string. Do not pass an unresolved CDK token.

The construct puts <service>.mcp-manifest.json with s3:PutObject on that one key, after serviceEndpoint deploys. The gateway's bucket policy accepts writes from any role in Flipdish's AWS Organization.

Removing the construct or the stack does not retire the tools. Nothing can delete the object from a service account. The gateway keeps advertising a manifest until its object is deleted (ADR-0008). To retire a service, ask the flipdish-mcp owners to delete <service>.mcp-manifest.json from each stage's bucket.

Two checks only the gateway runs: featureFlag must be registered in its Split filter, and a raw API Gateway host is accepted only on non-production gateway stages.

Test

const result = await reportMcp.callTool('get_report', { reportId: 'weekly-sales' }, { orgId: 'org123', brandId: 'br456' });

callTool runs a tool as tools/call would (validation, context, error mapping), without HTTP.