cd /news/ai-agents/why-toolgrain-keeps-mcp-tools-separa… · home › topics › ai-agents › article
[ARTICLE · art-158573] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Why Toolgrain keeps MCP tools separate from servers

A developer built Toolgrain, an MIT-licensed TypeScript toolkit that makes MCP tools standalone definitions bundling a description, Zod input/output schemas, and a handler, which servers then register under client-facing names. Published as @toolgrain/mcp and @toolgrain/node version 0.1.2, it validates both input and declared output at server execution while raw handler calls bypass that validation, and currently supports tool discovery and execution over stdio and independent HTTP POST requests, with sessions, SSE, resources, and prompts out of scope.

by read2 min views2 publishedOct 27, 2026

I started Toolgrain while building Pushwing and experimenting with Elysia for an MCP integration.

I wanted a TypeScript workflow where I could define a tool independently, get useful types from its input and output schemas, and reuse that definition across servers.

The approach I was using wasn’t giving me that combination, and the documentation I found didn’t give me a clear path to the structure I wanted. I thought a toolkit built around those needs could be useful.

The central design decision in Toolgrain is to make a tool a standalone definition. It bundles its description, Zod schemas, and handler. A server registers those definitions under the names exposed to MCP clients, and a transport handles how requests arrive.

Here’s a small inventory example using the published packages. It runs on Node.js 24.20.0 or later within 24.x, with TypeScript strict mode.

In a new directory:

npm init -y
npm install @toolgrain/mcp@0.1.2 @toolgrain/node@0.1.2 zod@^4.6.6
npm install --save-dev typescript @types/node@^24.10.0

Save this as server.mts:

import { createServer, tool } from "@toolgrain/mcp";
import { stdio } from "@toolgrain/node";
import { z } from "zod";

const inventory = { notebook: 12, pencil: 48 };

const getStock = tool({
  description: "Look up the stock available for a product",
  annotations: { readOnlyHint: true },
  input: z.object({ sku: z.enum(["notebook", "pencil"]) }),
  output: z.object({
    sku: z.string(),
    quantity: z.number().int().nonnegative(),
  }),
  execute: ({ sku }) => ({ sku, quantity: inventory[sku] }),
});

const server = createServer({
  name: "inventory-demo",
  version: "1.0.0",
  tools: { get_stock: getStock },
});

await server.listen(stdio());

Compile it:

npx tsc server.mts --strict --module NodeNext --target ES2022 --types node

Then call the tool with MCP Inspector’s CLI:

npx --yes @modelcontextprotocol/inspector@2.11.0 --cli \
  --protocol-era modern --format json \
  --method tools/call --tool-name get_stock \
  --tool-args-json '{"sku":"pencil"}' \
  node server.mjs

Inspector starts the server, calls the tool, and exits. The response’s result.structuredContent contains:

{ "sku": "pencil", "quantity": 48 }

A few details explain the separation:

getStock is the TypeScript value; get_stock is the registered name that MCP clients discover and call.sku type. Server execution validates both input and the declared output.execute() calls are raw handler calls. They bypass server validation. In an application, the handler can call an existing service instead of reading the in-memory inventory. Toolgrain also has context providers for application dependencies.

The current implementation focuses on tool discovery and execution over stdio and independent HTTP POST requests with JSON responses. Sessions, SSE, resources, and prompts are outside its current scope.

The separation between tool definitions, server execution, and transports came directly from the workflow I wanted while building Pushwing.

The Toolgrain source is MIT-licensed. Its tool authoring guide documents the validation and execution behavior in more detail.

How do you organize tool definitions when the same application operation needs to be exposed through more than one MCP server?

This article was drafted with AI assistance from my description of the project. The example was verified against Toolgrain 0.1.2.

── more in #ai-agents 4 stories · sorted by recency
── more on @toolgrain 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/why-toolgrain-keeps-…] indexed:0 read:2min 2026-10-27 · —