[{"data":1,"prerenderedAt":838},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-mcp\u002Fguides\u002Fserver":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":837,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-mcp\u002Fguides\u002Fserver.md",{},"Run an MCP server",{"type":8,"value":9,"toc":827},"minimark",[10,14,569,573,588,618,622,633,811],[11,12,13],"p",{},"Generate and start an MCP server with typed tools and an HTTP client.",[15,16,18,23,31,323,351,355,358,409,412,425,432,436,442,541],"steps",{"level":17},"2",[19,20,22],"h2",{"id":21},"generate-the-server","Generate the server",[11,24,25,26,30],{},"Register TypeScript types, Zod schemas, and an Axios or Fetch client alongside ",[27,28,29],"code",{},"pluginMcp",". A single registered client is detected automatically.",[32,33,38],"pre",{"language":34,"filename":35,"code":36,"class":37},"typescript","kubb.config.ts","import { defineConfig } from 'kubb\u002Fconfig'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginZod } from '@kubb\u002Fplugin-zod'\nimport { pluginAxios } from '@kubb\u002Fplugin-axios'\nimport { pluginMcp } from '@kubb\u002Fplugin-mcp'\n\nexport default defineConfig({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fsrc\u002Fgen' },\n  plugins: [\n    pluginTs({ output: { path: 'types', mode: 'directory' } }),\n    pluginZod(),\n    pluginAxios({ baseURL: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' }),\n    pluginMcp({ output: { path: 'mcp', mode: 'directory' } }),\n  ],\n})","highlights",[27,39,41,68,69,68,85,68,101,68,117,68,133,68,135,68,150,68,167,68,191,68,203,68,243,68,255,68,277,68,310,68,319],{"class":40},"language-typescript",[42,43,46,50,54,58,61,64],"span",{"class":44,"style":45},"line","display: inline",[42,47,49],{"style":48},"color:#d73a49;--hls-dark:#f97583","import ",[42,51,53],{"style":52},"color:#005cc5;--hls-dark:#79b8ff","{ ",[42,55,57],{"style":56},"color:#24292e;--hls-dark:#e1e4e8","defineConfig ",[42,59,60],{"style":52},"} ",[42,62,63],{"style":48},"from ",[42,65,67],{"style":66},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[42,70,71,73,75,78,80,82],{"class":44,"style":45},[42,72,49],{"style":48},[42,74,53],{"style":52},[42,76,77],{"style":56},"pluginTs ",[42,79,60],{"style":52},[42,81,63],{"style":48},[42,83,84],{"style":66},"'@kubb\u002Fplugin-ts'",[42,86,87,89,91,94,96,98],{"class":44,"style":45},[42,88,49],{"style":48},[42,90,53],{"style":52},[42,92,93],{"style":56},"pluginZod ",[42,95,60],{"style":52},[42,97,63],{"style":48},[42,99,100],{"style":66},"'@kubb\u002Fplugin-zod'",[42,102,103,105,107,110,112,114],{"class":44,"style":45},[42,104,49],{"style":48},[42,106,53],{"style":52},[42,108,109],{"style":56},"pluginAxios ",[42,111,60],{"style":52},[42,113,63],{"style":48},[42,115,116],{"style":66},"'@kubb\u002Fplugin-axios'",[42,118,119,121,123,126,128,130],{"class":44,"style":45},[42,120,49],{"style":48},[42,122,53],{"style":52},[42,124,125],{"style":56},"pluginMcp ",[42,127,60],{"style":52},[42,129,63],{"style":48},[42,131,132],{"style":66},"'@kubb\u002Fplugin-mcp'",[42,134],{"class":44,"style":45},[42,136,137,140,143,147],{"class":44,"style":45},[42,138,139],{"style":48},"export ",[42,141,142],{"style":48},"default ",[42,144,146],{"style":145},"color:#6f42c1;--hls-dark:#b392f0","defineConfig",[42,148,149],{"style":52},"({",[42,151,152,155,158,161,164],{"class":44,"style":45},[42,153,154],{"style":52},"  ",[42,156,157],{"style":52},"input",[42,159,160],{"style":48},": ",[42,162,163],{"style":66},"'.\u002FpetStore.yaml'",[42,165,166],{"style":48},",",[42,168,169,171,174,176,178,181,183,186,189],{"class":44,"style":45},[42,170,154],{"style":48},[42,172,173],{"style":52},"output",[42,175,160],{"style":48},[42,177,53],{"style":52},[42,179,180],{"style":52},"path",[42,182,160],{"style":48},[42,184,185],{"style":66},"'.\u002Fsrc\u002Fgen' ",[42,187,188],{"style":52},"}",[42,190,166],{"style":48},[42,192,193,195,198,200],{"class":44,"style":45},[42,194,154],{"style":48},[42,196,197],{"style":52},"plugins",[42,199,160],{"style":48},[42,201,202],{"style":52},"[",[42,204,205,208,211,214,216,218,220,222,224,227,230,233,235,238,241],{"class":44,"style":45},[42,206,207],{"style":52},"    ",[42,209,210],{"style":145},"pluginTs",[42,212,213],{"style":52},"({ ",[42,215,173],{"style":52},[42,217,160],{"style":48},[42,219,53],{"style":52},[42,221,180],{"style":52},[42,223,160],{"style":48},[42,225,226],{"style":66},"'types'",[42,228,229],{"style":48},", ",[42,231,232],{"style":52},"mode",[42,234,160],{"style":48},[42,236,237],{"style":66},"'directory' ",[42,239,240],{"style":52},"} })",[42,242,166],{"style":48},[42,244,245,247,250,253],{"class":44,"style":45},[42,246,207],{"style":48},[42,248,249],{"style":145},"pluginZod",[42,251,252],{"style":52},"()",[42,254,166],{"style":48},[42,256,257,259,262,264,267,269,272,275],{"class":44,"style":45},[42,258,207],{"style":48},[42,260,261],{"style":145},"pluginAxios",[42,263,213],{"style":52},[42,265,266],{"style":52},"baseURL",[42,268,160],{"style":48},[42,270,271],{"style":66},"'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' ",[42,273,274],{"style":52},"})",[42,276,166],{"style":48},[42,278,279,281,283,285,287,289,291,293,295,298,300,302,304,306,308],{"class":44,"style":45},[42,280,207],{"style":48},[42,282,29],{"style":145},[42,284,213],{"style":52},[42,286,173],{"style":52},[42,288,160],{"style":48},[42,290,53],{"style":52},[42,292,180],{"style":52},[42,294,160],{"style":48},[42,296,297],{"style":66},"'mcp'",[42,299,229],{"style":48},[42,301,232],{"style":52},[42,303,160],{"style":48},[42,305,237],{"style":66},[42,307,240],{"style":52},[42,309,166],{"style":48},[42,311,312,314,317],{"class":44,"style":45},[42,313,154],{"style":48},[42,315,316],{"style":52},"]",[42,318,166],{"style":48},[42,320,321],{"class":44,"style":45},[42,322,274],{"style":52},[11,324,325,326,329,330,229,333,336,337,340,341,343,344,346,347,350],{},"Run ",[27,327,328],{},"kubb generate",". The plugin writes tool handlers, ",[27,331,332],{},"server.ts",[27,334,335],{},"start.ts",", and ",[27,338,339],{},".mcp.json",". Each generated handler calls its HTTP operation, forwards the cancellation signal, and throws for non-2xx responses. Tool results include text content and structured response data. ",[27,342,332],{}," registers tools with Zod input and output schemas, and ",[27,345,335],{}," calls its ",[27,348,349],{},"startServer()"," to serve them over stdio.",[19,352,354],{"id":353},"start-the-server","Start the server",[11,356,357],{},"Install the generated server's runtime dependencies and a TypeScript runner:",[32,359,363],{"language":360,"filename":361,"code":362,"class":37},"shell","Terminal","npm install @modelcontextprotocol\u002Fserver@^2 zod@^4.2 axios@^1.20.0\nnpm install -D tsx",[27,364,366,68,402],{"class":365},"language-shell",[42,367,368,371,374,377,380,383,386,389,391,394,397,399],{"class":44,"style":45},[42,369,370],{"style":145},"npm ",[42,372,373],{"style":56},"install ",[42,375,376],{"style":56},"@",[42,378,379],{"style":56},"modelcontextprotocol\u002Fserver",[42,381,382],{"style":56},"@^",[42,384,385],{"style":52},"2 ",[42,387,388],{"style":56},"zod",[42,390,382],{"style":56},[42,392,393],{"style":52},"4.2 ",[42,395,396],{"style":56},"axios",[42,398,382],{"style":56},[42,400,401],{"style":52},"1.20.0",[42,403,404,406],{"class":44,"style":45},[42,405,370],{"style":145},[42,407,408],{"style":56},"install -D tsx",[11,410,411],{},"Run the generated entry from the project root:",[32,413,415],{"language":360,"filename":361,"code":414,"class":37},"npx tsx src\u002Fgen\u002Fmcp\u002Fstart.ts",[27,416,417],{"class":365},[42,418,419,422],{"class":44,"style":45},[42,420,421],{"style":145},"npx ",[42,423,424],{"style":56},"tsx src\u002Fgen\u002Fmcp\u002Fstart.ts",[11,426,427,428,431],{},"The server reads MCP messages from stdin, prints nothing on startup, and logs transport errors to stderr. Press ",[27,429,430],{},"Ctrl+C"," to stop it.",[19,433,435],{"id":434},"connect-a-client","Connect a client",[11,437,438,439,441],{},"The generated ",[27,440,339],{}," runs the same command:",[32,443,447],{"language":444,"filename":445,"code":446,"class":37},"json","src\u002Fgen\u002Fmcp\u002F.mcp.json","{\n  \"mcpServers\": {\n    \"Swagger Petstore\": {\n      \"type\": \"stdio\",\n      \"command\": \"npx\",\n      \"args\": [\"tsx\", \".\u002Fsrc\u002Fgen\u002Fmcp\u002Fstart.ts\"]\n    }\n  }\n}",[27,448,450,68,455,68,466,68,477,68,492,68,506,68,527,68,532,68,537],{"class":449},"language-json",[42,451,452],{"class":44,"style":45},[42,453,454],{"style":52},"{",[42,456,457,459,462,464],{"class":44,"style":45},[42,458,154],{"style":52},[42,460,461],{"style":52},"\"mcpServers\"",[42,463,160],{"style":48},[42,465,454],{"style":52},[42,467,468,470,473,475],{"class":44,"style":45},[42,469,207],{"style":52},[42,471,472],{"style":52},"\"Swagger Petstore\"",[42,474,160],{"style":48},[42,476,454],{"style":52},[42,478,479,482,485,487,490],{"class":44,"style":45},[42,480,481],{"style":52},"      ",[42,483,484],{"style":52},"\"type\"",[42,486,160],{"style":48},[42,488,489],{"style":66},"\"stdio\"",[42,491,166],{"style":48},[42,493,494,496,499,501,504],{"class":44,"style":45},[42,495,481],{"style":48},[42,497,498],{"style":52},"\"command\"",[42,500,160],{"style":48},[42,502,503],{"style":66},"\"npx\"",[42,505,166],{"style":48},[42,507,508,510,513,515,517,520,522,525],{"class":44,"style":45},[42,509,481],{"style":48},[42,511,512],{"style":52},"\"args\"",[42,514,160],{"style":48},[42,516,202],{"style":52},[42,518,519],{"style":66},"\"tsx\"",[42,521,229],{"style":48},[42,523,524],{"style":66},"\".\u002Fsrc\u002Fgen\u002Fmcp\u002Fstart.ts\"",[42,526,316],{"style":52},[42,528,529],{"class":44,"style":45},[42,530,531],{"style":52},"    }",[42,533,534],{"class":44,"style":45},[42,535,536],{"style":52},"  }",[42,538,539],{"class":44,"style":45},[42,540,188],{"style":52},[11,542,543,544,547,548,551,552,555,556,558,559,561,562,565,566,568],{},"The server name comes from ",[27,545,546],{},"info.title"," in your OpenAPI spec. MCP clients start the command from their own working directory, so the ",[27,549,550],{},"args"," path is relative to the Kubb ",[27,553,554],{},"root",", not to the ",[27,557,339],{}," folder. Claude Code reads ",[27,560,339],{}," from the project root, so copy the entry under ",[27,563,564],{},"mcpServers"," into that file. For a client that starts in another folder, such as Claude Desktop, use an absolute path to ",[27,567,335],{},".",[19,570,572],{"id":571},"use-your-own-entry-file","Use your own entry file",[11,574,575,576,579,580,582,583,585,586,568],{},"To run setup code first, such as loading environment variables, import ",[27,577,578],{},"startServer"," from the generated ",[27,581,332],{}," in your own entry file and point ",[27,584,550],{}," at that file instead of ",[27,587,335],{},[32,589,592],{"language":34,"filename":590,"code":591,"class":37},"mcp.ts","import { startServer } from '.\u002Fsrc\u002Fgen\u002Fmcp\u002Fserver'\n\nstartServer()",[27,593,594,68,610,68,612],{"class":40},[42,595,596,598,600,603,605,607],{"class":44,"style":45},[42,597,49],{"style":48},[42,599,53],{"style":52},[42,601,602],{"style":56},"startServer ",[42,604,60],{"style":52},[42,606,63],{"style":48},[42,608,609],{"style":66},"'.\u002Fsrc\u002Fgen\u002Fmcp\u002Fserver'",[42,611],{"class":44,"style":45},[42,613,614,616],{"class":44,"style":45},[42,615,578],{"style":145},[42,617,252],{"style":52},[19,619,621],{"id":620},"select-a-client","Select a client",[11,623,624,625,632],{},"When both HTTP plugins are registered, set ",[626,627,629],"a",{"href":628},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-mcp\u002Foptions#client",[27,630,631],{},"client"," explicitly. Give each client a different output directory so their generated files do not overwrite each other.",[32,634,636],{"language":34,"filename":35,"code":635,"class":37},"import { pluginAxios } from '@kubb\u002Fplugin-axios'\nimport { pluginFetch } from '@kubb\u002Fplugin-fetch'\nimport { pluginMcp } from '@kubb\u002Fplugin-mcp'\n\nconst clients = [\n  pluginAxios({ output: { path: 'clients-axios', mode: 'directory' } }),\n  pluginFetch({ output: { path: 'clients-fetch', mode: 'directory' } }),\n  pluginMcp({ output: { path: 'mcp', mode: 'directory' }, client: 'axios' }),\n]",[27,637,638,68,652,68,668,68,682,68,684,68,697,68,730,68,764,68,807],{"class":40},[42,639,640,642,644,646,648,650],{"class":44,"style":45},[42,641,49],{"style":48},[42,643,53],{"style":52},[42,645,109],{"style":56},[42,647,60],{"style":52},[42,649,63],{"style":48},[42,651,116],{"style":66},[42,653,654,656,658,661,663,665],{"class":44,"style":45},[42,655,49],{"style":48},[42,657,53],{"style":52},[42,659,660],{"style":56},"pluginFetch ",[42,662,60],{"style":52},[42,664,63],{"style":48},[42,666,667],{"style":66},"'@kubb\u002Fplugin-fetch'",[42,669,670,672,674,676,678,680],{"class":44,"style":45},[42,671,49],{"style":48},[42,673,53],{"style":52},[42,675,125],{"style":56},[42,677,60],{"style":52},[42,679,63],{"style":48},[42,681,132],{"style":66},[42,683],{"class":44,"style":45},[42,685,686,689,692,695],{"class":44,"style":45},[42,687,688],{"style":48},"const ",[42,690,691],{"style":56},"clients ",[42,693,694],{"style":48},"= ",[42,696,202],{"style":52},[42,698,699,701,703,705,707,709,711,713,715,718,720,722,724,726,728],{"class":44,"style":45},[42,700,154],{"style":52},[42,702,261],{"style":145},[42,704,213],{"style":52},[42,706,173],{"style":52},[42,708,160],{"style":48},[42,710,53],{"style":52},[42,712,180],{"style":52},[42,714,160],{"style":48},[42,716,717],{"style":66},"'clients-axios'",[42,719,229],{"style":48},[42,721,232],{"style":52},[42,723,160],{"style":48},[42,725,237],{"style":66},[42,727,240],{"style":52},[42,729,166],{"style":48},[42,731,732,734,737,739,741,743,745,747,749,752,754,756,758,760,762],{"class":44,"style":45},[42,733,154],{"style":48},[42,735,736],{"style":145},"pluginFetch",[42,738,213],{"style":52},[42,740,173],{"style":52},[42,742,160],{"style":48},[42,744,53],{"style":52},[42,746,180],{"style":52},[42,748,160],{"style":48},[42,750,751],{"style":66},"'clients-fetch'",[42,753,229],{"style":48},[42,755,232],{"style":52},[42,757,160],{"style":48},[42,759,237],{"style":66},[42,761,240],{"style":52},[42,763,166],{"style":48},[42,765,766,768,770,772,774,776,778,780,782,784,786,788,790,792,794,796,798,800,803,805],{"class":44,"style":45},[42,767,154],{"style":48},[42,769,29],{"style":145},[42,771,213],{"style":52},[42,773,173],{"style":52},[42,775,160],{"style":48},[42,777,53],{"style":52},[42,779,180],{"style":52},[42,781,160],{"style":48},[42,783,297],{"style":66},[42,785,229],{"style":48},[42,787,232],{"style":52},[42,789,160],{"style":48},[42,791,237],{"style":66},[42,793,188],{"style":52},[42,795,229],{"style":48},[42,797,631],{"style":52},[42,799,160],{"style":48},[42,801,802],{"style":66},"'axios' ",[42,804,274],{"style":52},[42,806,166],{"style":48},[42,808,809],{"class":44,"style":45},[42,810,316],{"style":52},[11,812,813,814,816,817,819,820,823,824,568],{},"Add these entries alongside ",[27,815,210],{}," and ",[27,818,249],{}," in ",[27,821,822],{},"defineConfig.plugins",". The handlers import operations from ",[27,825,826],{},"clients-axios",{"title":828,"searchDepth":829,"depth":829,"links":830},"",5,[831,833,834,835,836],{"id":21,"depth":832,"text":22},2,{"id":353,"depth":832,"text":354},{"id":434,"depth":832,"text":435},{"id":571,"depth":832,"text":572},{"id":620,"depth":832,"text":621},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-mcp\u002Fguides\u002Fserver",1793639048155]