
@rtorcato/api-mcp
by rtorcato
@rtorcato/api-mcp
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.
NOASSERTION★ 198,904

@modelcontextprotocol/server-everything
OfficialMCP server that exercises all the features of the MCP protocol
★ 89,105

@modelcontextprotocol/server-filesystem
OfficialMCP server for filesystem access
SEE LICENSE IN LICENSE★ 89,105