Home / Servers

@rtorcato/api-mcp

by rtorcato

@rtorcato/api-mcp

npm version npm downloads Bundle size License: MIT

Two tiny result helpers for MCP tool handlers built on the official @modelcontextprotocol/sdk.

The SDK already owns tool/resource registration and transports, so this package is deliberately minimal — it only removes the asText / error-result boilerplate every server rewrites. Everything else, use the SDK directly.

Install

pnpm add @rtorcato/api-mcp @modelcontextprotocol/sdk

@modelcontextprotocol/sdk is a peer dependency — you control the version.

Usage

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { asText, mcpError } from '@rtorcato/api-mcp'
import { z } from 'zod'

const server = new McpServer({ name: 'example', version: '0.0.0' })
const items = new Map<string, { id: string; name: string }>()

server.registerTool('list_items', { title: 'List items' }, async () =>
  asText([...items.values()])
)

server.registerTool(
  'get_item',
  { title: 'Get item', inputSchema: { id: z.string() } },
  async ({ id }) => {
    const item = items.get(id)
    return item ? asText(item) : mcpError(`Item ${id} not found`)
  }
)

API

  • asText(value) → success result: { content: [{ type: 'text', text: JSON.stringify(value) }] }.
  • mcpError(text) → error result: { isError: true, content: [{ type: 'text', text }] }.

Both return the SDK's CallToolResult type, so they drop straight into a registerTool handler.

Related servers

n8n

by n8n-io

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

NOASSERTION198,904

@modelcontextprotocol/server-everything

Official

by modelcontextprotocol

MCP server that exercises all the features of the MCP protocol

89,105

@modelcontextprotocol/server-filesystem

Official

by modelcontextprotocol

MCP server for filesystem access

SEE LICENSE IN LICENSE89,105

mcp-server-fetch

Official

by modelcontextprotocol

A Model Context Protocol server providing tools to fetch and convert web content for usage by LLMs

89,105