Skip to content

Commit 7fb6c93

Browse files
committed
feat: use TOON format for MCP responses
1 parent eac0af5 commit 7fb6c93

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@modelcontextprotocol/sdk": "catalog:",
1818
"@nuxt/content": "catalog:",
19+
"@toon-format/toon": "^1.2.0",
1920
"better-sqlite3": "catalog:",
2021
"nuxt": "catalog:",
2122
"zod": "catalog:"

server/server/routes/mcp.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { IncomingMessage, ServerResponse } from 'node:http'
22
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
4+
import { encode } from '@toon-format/toon'
45
import { z } from 'zod'
56

67
export default defineEventHandler(async (event) => {
@@ -20,16 +21,16 @@ export default defineEventHandler(async (event) => {
2021
{
2122
title: 'Nimiq Documentation Page Index',
2223
description:
23-
'JSON list of all available Nimiq documentation pages across 6 modules (web-client, rpc, protocol, hub, nodes, nimiq-utils). Each entry includes title, URL, description, and module. Use to discover available documentation or find specific topics. Returns comprehensive metadata for all ~50+ documentation pages.',
24+
'TOON-formatted list of all available Nimiq documentation pages across 6 modules (web-client, rpc, protocol, hub, nodes, nimiq-utils). Each entry includes title, URL, description, and module. Use to discover available documentation or find specific topics. Returns comprehensive metadata for all ~50+ documentation pages in token-efficient TOON format.',
2425
},
2526
async (uri) => {
2627
const docs = await $fetch('/api/mcp/list-documentation-pages')
2728
return {
2829
contents: [
2930
{
3031
uri: uri.href,
31-
mimeType: 'application/json',
32-
text: JSON.stringify(docs),
32+
mimeType: 'text/plain',
33+
text: encode(docs),
3334
},
3435
],
3536
}
@@ -41,16 +42,16 @@ export default defineEventHandler(async (event) => {
4142
'resource://nimiq/tutorials',
4243
{
4344
title: 'Nimiq Tutorial Catalog',
44-
description: 'JSON list of hands-on tutorials for Nimiq blockchain development. Each entry includes title, URL, description, difficulty, and topics covered. Use when users need step-by-step guided learning (not just concept explanations). Returns structured tutorial metadata for discovery and selection.',
45+
description: 'TOON-formatted list of hands-on tutorials for Nimiq blockchain development. Each entry includes title, URL, description, difficulty, and topics covered. Use when users need step-by-step guided learning (not just concept explanations). Returns structured tutorial metadata for discovery and selection in token-efficient TOON format.',
4546
},
4647
async (uri) => {
4748
const tutorials = await $fetch('/api/mcp/list-tutorials')
4849
return {
4950
contents: [
5051
{
5152
uri: uri.href,
52-
mimeType: 'application/json',
53-
text: JSON.stringify(tutorials),
53+
mimeType: 'text/plain',
54+
text: encode(tutorials),
5455
},
5556
],
5657
}
@@ -62,16 +63,16 @@ export default defineEventHandler(async (event) => {
6263
'resource://nimiq/open-rpc-specification-document',
6364
{
6465
title: 'Nimiq JSON-RPC API Specification',
65-
description: 'Complete OpenRPC specification document containing all 125 Nimiq JSON-RPC methods with schemas, parameters, return types, examples, and error codes. Use to understand available RPC methods, their exact parameter schemas, or generate type-safe API clients. Returns full OpenRPC 1.3 specification in JSON format.',
66+
description: 'Complete OpenRPC specification document containing all 125 Nimiq JSON-RPC methods with schemas, parameters, return types, examples, and error codes. Use to understand available RPC methods, their exact parameter schemas, or generate type-safe API clients. Returns full OpenRPC 1.3 specification in TOON format for token efficiency.',
6667
},
6768
async (uri) => {
6869
const spec = await $fetch('/api/mcp/open-rpc-specification-document')
6970
return {
7071
contents: [
7172
{
7273
uri: uri.href,
73-
mimeType: 'application/json',
74-
text: JSON.stringify(spec),
74+
mimeType: 'text/plain',
75+
text: encode(spec),
7576
},
7677
],
7778
}
@@ -149,7 +150,7 @@ export default defineEventHandler(async (event) => {
149150
try {
150151
const docs = await $fetch('/api/mcp/list-documentation-pages', { query: { module } })
151152
return {
152-
content: [{ type: 'text', text: JSON.stringify(docs, null, 2) }],
153+
content: [{ type: 'text', text: encode(docs) }],
153154
}
154155
}
155156
catch (error: any) {
@@ -197,7 +198,7 @@ export default defineEventHandler(async (event) => {
197198
try {
198199
const tutorials = await $fetch('/api/mcp/list-tutorials')
199200
return {
200-
content: [{ type: 'text', text: JSON.stringify(tutorials, null, 2) }],
201+
content: [{ type: 'text', text: encode(tutorials) }],
201202
}
202203
}
203204
catch (error: any) {
@@ -247,7 +248,7 @@ export default defineEventHandler(async (event) => {
247248
try {
248249
const methods = await $fetch('/api/mcp/list-rpc-methods', { query: { tags } })
249250
return {
250-
content: [{ type: 'text', text: JSON.stringify(methods, null, 2) }],
251+
content: [{ type: 'text', text: encode(methods) }],
251252
}
252253
}
253254
catch (error: any) {

0 commit comments

Comments
 (0)