[{"data":1,"prerenderedAt":1553},["ShallowReactive",2],{"series-\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent":3,"series-context-\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web":1418},{"id":4,"title":5,"body":6,"contentId":1401,"date":1402,"description":1403,"extension":1404,"github":1405,"meetTheInstructor":1407,"meta":1408,"navigation":189,"part":108,"path":1409,"rawbody":1410,"robots":1407,"schemaOrg":1407,"seo":1411,"seriesSlug":1412,"sitemap":1413,"stem":1416,"subtitle":1407,"topics":1407,"__hash__":1417},"series\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent.md","MCP to Provide Additional Capabilities to the AI Agent",{"type":7,"value":8,"toc":1395},"minimark",[9,21,24,35,38,67,70,75,78,115,118,134,137,144,280,283,291,294,564,579,582,585,590,593,606,611,614,629,632,636,639,650,1077,1083,1368,1375,1378,1388,1391],[10,11,12,13,20],"p",{},"We built our first AI Agent with an addition tool. In this article, we will move that tool into an ",[14,15,19],"a",{"href":16,"rel":17},"https:\u002F\u002Fmodelcontextprotocol.io\u002Fdocs\u002Fgetting-started\u002Fintro",[18],"nofollow","MCP server",", where it can be discovered and used through a standard protocol.",[10,22,23],{},"A quick reminder about MCP: MCP is an open-source standard for connecting AI applications to external systems. An MCP server provides tools, while an MCP client connects to that server and calls its tools on the agent's behalf. In this series, our AI application contains the agent and its MCP client; the MCP server exposes the capabilities the agent needs. Visually, it looks like this:",[25,26,27,32],"figure",{},[28,29],"img",{"alt":30,"src":31},"AI application interacting with the real world through MCP.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Fmcp.webp",[33,34,30],"figcaption",{},[10,36,37],{},"You might wonder why we need an MCP server. We do not strictly need one for this small addition tool: a direct tool is simpler when the capability belongs only to one tightly coupled application. MCP becomes useful when a capability should be shared, independently deployed, or consumed by compatible clients.",[39,40,41,55,61],"ol",{},[42,43,44,48,49,54],"li",{},[45,46,47],"strong",{},"Support compatible clients",": By providing MCP, you allow AI applications and coding tools that support the protocol to use your capabilities. For example, a ",[14,50,53],{"href":51,"rel":52},"https:\u002F\u002Fui.nuxt.com\u002Fdocs\u002Fgetting-started\u002Fai\u002Fmcp",[18],"component-library MCP server"," can make its documentation and tools available in a code editor.",[42,56,57,60],{},[45,58,59],{},"Use external MCP servers",": Your agent can also connect to an MCP server you did not create to integrate with an existing system or third-party capability.",[42,62,63,66],{},[45,64,65],{},"Decouple capabilities",": The agent only needs to know a tool's name, description, input, and output. The MCP server owns its implementation and can evolve independently.",[10,68,69],{},"For this series, MCP gives us a clear boundary between the agent and the capabilities it can use.",[71,72,74],"h2",{"id":73},"building-the-mcp-server","Building the MCP server",[10,76,77],{},"Within our Nitro application, we can create a new route for the MCP server.",[79,80,86],"pre",{"className":81,"code":82,"filename":83,"language":84,"meta":85,"style":85},"language-bash shiki shiki-themes github-light github-light github-dark","mkdir -p server\u002Froutes\ntouch server\u002Froutes\u002Fmcp.ts\n","terminal","bash","",[87,88,89,106],"code",{"__ignoreMap":85},[90,91,94,98,102],"span",{"class":92,"line":93},"line",1,[90,95,97],{"class":96},"snPdu","mkdir",[90,99,101],{"class":100},"sBjJW"," -p",[90,103,105],{"class":104},"sIIMD"," server\u002Froutes\n",[90,107,109,112],{"class":92,"line":108},2,[90,110,111],{"class":96},"touch",[90,113,114],{"class":104}," server\u002Froutes\u002Fmcp.ts\n",[10,116,117],{},"Then, we have to install the MCP SDK:",[79,119,121],{"className":81,"code":120,"filename":83,"language":84,"meta":85,"style":85},"pnpm add @modelcontextprotocol\u002Fsdk@^1.29.0\n",[87,122,123],{"__ignoreMap":85},[90,124,125,128,131],{"class":92,"line":93},[90,126,127],{"class":96},"pnpm",[90,129,130],{"class":104}," add",[90,132,133],{"class":104}," @modelcontextprotocol\u002Fsdk@^1.29.0\n",[10,135,136],{},"This is the official TypeScript SDK for building MCP servers.",[10,138,139,140,143],{},"Now, we can create our MCP server within the ",[87,141,142],{},"server\u002Froutes\u002Fmcp.ts"," file:",[79,145,154],{"className":146,"code":147,"filename":142,"highlights":148,"language":153,"meta":85,"style":85},"language-ts shiki shiki-themes github-light github-light github-dark","import { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { defineEventHandler } from 'h3'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n})\n",[149,150,151,152],5,6,7,8,"ts",[87,155,156,172,184,191,225,247,259,268,274],{"__ignoreMap":85},[90,157,158,162,166,169],{"class":92,"line":93},[90,159,161],{"class":160},"s8jYJ","import",[90,163,165],{"class":164},"sxrX7"," { McpServer } ",[90,167,168],{"class":160},"from",[90,170,171],{"class":104}," '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\n",[90,173,174,176,179,181],{"class":92,"line":108},[90,175,161],{"class":160},[90,177,178],{"class":164}," { defineEventHandler } ",[90,180,168],{"class":160},[90,182,183],{"class":104}," 'h3'\n",[90,185,187],{"class":92,"line":186},3,[90,188,190],{"emptyLinePlaceholder":189},true,"\n",[90,192,194,197,200,203,206,209,212,216,219,222],{"class":92,"line":193},4,[90,195,196],{"class":160},"export",[90,198,199],{"class":160}," default",[90,201,202],{"class":96}," defineEventHandler",[90,204,205],{"class":164},"(",[90,207,208],{"class":160},"async",[90,210,211],{"class":164}," (",[90,213,215],{"class":214},"sP4rz","event",[90,217,218],{"class":164},") ",[90,220,221],{"class":160},"=>",[90,223,224],{"class":164}," {\n",[90,226,229,232,235,238,241,244],{"class":227,"line":149},[92,228],"highlight",[90,230,231],{"class":160},"  const",[90,233,234],{"class":100}," server",[90,236,237],{"class":160}," =",[90,239,240],{"class":160}," new",[90,242,243],{"class":96}," McpServer",[90,245,246],{"class":164},"({\n",[90,248,250,253,256],{"class":249,"line":150},[92,228],[90,251,252],{"class":164},"    name: ",[90,254,255],{"class":104},"'ai-agent'",[90,257,258],{"class":164},",\n",[90,260,262,265],{"class":261,"line":151},[92,228],[90,263,264],{"class":164},"    version: ",[90,266,267],{"class":104},"'1.0.0'\n",[90,269,271],{"class":270,"line":152},[92,228],[90,272,273],{"class":164},"  })\n",[90,275,277],{"class":92,"line":276},9,[90,278,279],{"class":164},"})\n",[10,281,282],{},"We now have an MCP server object, but it cannot receive requests yet. MCP separates the server, which defines the protocol capabilities and tools, from the transport, which carries requests and responses. In our case, the Nitro route will host a Streamable HTTP transport so an MCP client can reach the server over HTTP.",[284,285,288],"callout",{"color":286,"icon":287},"info","i-ph-info-duotone",[10,289,290],{},"Streamable HTTP is useful here because it allows a remotely hosted MCP server to communicate through regular HTTP requests and responses.",[10,292,293],{},"Fortunately, the MCP SDK provides everything we need to add an HTTP transport layer.",[79,295,313],{"className":146,"code":296,"filename":297,"highlights":298,"language":153,"meta":85,"style":85},"import { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002FstreamableHttp.js'\nimport { defineEventHandler, readBody } from 'h3'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n\n  const transport = new StreamableHTTPServerTransport({\n    sessionIdGenerator: undefined\n  })\n\n  event.node.res.on('close', () => {\n    transport.close()\n    server.close()\n  })\n\n  await server.connect(transport)\n\n  const body = await readBody(event)\n\n  await transport.handleRequest(event.node.req, event.node.res, body)\n})\n","Example",[186,299,300,301,302,303,304,305,306,307,308,309,310,311,312],11,12,13,14,15,16,17,18,19,20,21,22,23,24,[87,314,315,325,337,349,353,375,389,397,403,407,412,429,438,443,448,469,481,491,496,501,516,521,540,545,559],{"__ignoreMap":85},[90,316,317,319,321,323],{"class":92,"line":93},[90,318,161],{"class":160},[90,320,165],{"class":164},[90,322,168],{"class":160},[90,324,171],{"class":104},[90,326,327,329,332,334],{"class":92,"line":108},[90,328,161],{"class":160},[90,330,331],{"class":164}," { StreamableHTTPServerTransport } ",[90,333,168],{"class":160},[90,335,336],{"class":104}," '@modelcontextprotocol\u002Fsdk\u002Fserver\u002FstreamableHttp.js'\n",[90,338,340,342,345,347],{"class":339,"line":186},[92,228],[90,341,161],{"class":160},[90,343,344],{"class":164}," { defineEventHandler, readBody } ",[90,346,168],{"class":160},[90,348,183],{"class":104},[90,350,351],{"class":92,"line":193},[90,352,190],{"emptyLinePlaceholder":189},[90,354,355,357,359,361,363,365,367,369,371,373],{"class":92,"line":149},[90,356,196],{"class":160},[90,358,199],{"class":160},[90,360,202],{"class":96},[90,362,205],{"class":164},[90,364,208],{"class":160},[90,366,211],{"class":164},[90,368,215],{"class":214},[90,370,218],{"class":164},[90,372,221],{"class":160},[90,374,224],{"class":164},[90,376,377,379,381,383,385,387],{"class":92,"line":150},[90,378,231],{"class":160},[90,380,234],{"class":100},[90,382,237],{"class":160},[90,384,240],{"class":160},[90,386,243],{"class":96},[90,388,246],{"class":164},[90,390,391,393,395],{"class":92,"line":151},[90,392,252],{"class":164},[90,394,255],{"class":104},[90,396,258],{"class":164},[90,398,399,401],{"class":92,"line":152},[90,400,264],{"class":164},[90,402,267],{"class":104},[90,404,405],{"class":92,"line":276},[90,406,273],{"class":164},[90,408,410],{"class":92,"line":409},10,[90,411,190],{"emptyLinePlaceholder":189},[90,413,415,417,420,422,424,427],{"class":414,"line":299},[92,228],[90,416,231],{"class":160},[90,418,419],{"class":100}," transport",[90,421,237],{"class":160},[90,423,240],{"class":160},[90,425,426],{"class":96}," StreamableHTTPServerTransport",[90,428,246],{"class":164},[90,430,432,435],{"class":431,"line":300},[92,228],[90,433,434],{"class":164},"    sessionIdGenerator: ",[90,436,437],{"class":100},"undefined\n",[90,439,441],{"class":440,"line":301},[92,228],[90,442,273],{"class":164},[90,444,446],{"class":445,"line":302},[92,228],[90,447,190],{"emptyLinePlaceholder":189},[90,449,451,454,457,459,462,465,467],{"class":450,"line":303},[92,228],[90,452,453],{"class":164},"  event.node.res.",[90,455,456],{"class":96},"on",[90,458,205],{"class":164},[90,460,461],{"class":104},"'close'",[90,463,464],{"class":164},", () ",[90,466,221],{"class":160},[90,468,224],{"class":164},[90,470,472,475,478],{"class":471,"line":304},[92,228],[90,473,474],{"class":164},"    transport.",[90,476,477],{"class":96},"close",[90,479,480],{"class":164},"()\n",[90,482,484,487,489],{"class":483,"line":305},[92,228],[90,485,486],{"class":164},"    server.",[90,488,477],{"class":96},[90,490,480],{"class":164},[90,492,494],{"class":493,"line":306},[92,228],[90,495,273],{"class":164},[90,497,499],{"class":498,"line":307},[92,228],[90,500,190],{"emptyLinePlaceholder":189},[90,502,504,507,510,513],{"class":503,"line":308},[92,228],[90,505,506],{"class":160},"  await",[90,508,509],{"class":164}," server.",[90,511,512],{"class":96},"connect",[90,514,515],{"class":164},"(transport)\n",[90,517,519],{"class":518,"line":309},[92,228],[90,520,190],{"emptyLinePlaceholder":189},[90,522,524,526,529,531,534,537],{"class":523,"line":310},[92,228],[90,525,231],{"class":160},[90,527,528],{"class":100}," body",[90,530,237],{"class":160},[90,532,533],{"class":160}," await",[90,535,536],{"class":96}," readBody",[90,538,539],{"class":164},"(event)\n",[90,541,543],{"class":542,"line":311},[92,228],[90,544,190],{"emptyLinePlaceholder":189},[90,546,548,550,553,556],{"class":547,"line":312},[92,228],[90,549,506],{"class":160},[90,551,552],{"class":164}," transport.",[90,554,555],{"class":96},"handleRequest",[90,557,558],{"class":164},"(event.node.req, event.node.res, body)\n",[90,560,562],{"class":92,"line":561},25,[90,563,279],{"class":164},[10,565,566,567,570,571,574,575,578],{},"With ",[87,568,569],{},"server.connect(transport)",", we attach the server to the HTTP transport. With ",[87,572,573],{},"transport.handleRequest(event.node.req, event.node.res, body)",", we pass the incoming request to that transport, which sends the response back to the client. This example creates a stateless transport for each request, so ",[87,576,577],{},"sessionIdGenerator: undefined"," disables session IDs. When the response ends or terminates prematurely, we close the transport and server to free their resources.",[10,580,581],{},"The request body is important because tool calls can include input parameters.",[10,583,584],{},"With this setup, we can now try the MCP.",[586,587,589],"h3",{"id":588},"trying-the-mcp","Trying the MCP",[10,591,592],{},"To try the MCP, we can use the official MCP Inspector:",[79,594,596],{"className":81,"code":595,"filename":83,"language":84,"meta":85,"style":85},"npx @modelcontextprotocol\u002Finspector@latest\n",[87,597,598],{"__ignoreMap":85},[90,599,600,603],{"class":92,"line":93},[90,601,602],{"class":96},"npx",[90,604,605],{"class":104}," @modelcontextprotocol\u002Finspector@latest\n",[284,607,608],{"color":286,"icon":287},[10,609,610],{},"Use the inspector to verify an MCP server before connecting it to an AI application. A model may decide not to call a particular tool, while the inspector lets you test the protocol and tools directly.",[10,612,613],{},"Then, we can enter the MCP URL and ping the server to make sure it's working.",[25,615,616,617,616,626],{},"\n  ",[618,619,620,621,616],"video",{"autoPlay":189,"loop":189,"muted":189,"playsInline":189},"\n    ",[622,623],"source",{"src":624,"type":625},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Fpinging-server.mp4","video\u002Fmp4",[33,627,628],{},"Pinging the MCP server.",[10,630,631],{},"The server is now reachable through its HTTP transport.",[586,633,635],{"id":634},"adding-a-tool","Adding a tool",[10,637,638],{},"Now that we have a working MCP server, we can move our addition tool from the AI Agent to the MCP server.",[10,640,641,642,645,646,649],{},"Within the ",[87,643,644],{},"server\u002Fapi\u002Fchat.ts"," file, remove ",[87,647,648],{},"tool"," from the AI SDK import, remove the Zod import, and delete the addition tool registration:",[79,651,654],{"className":652,"code":653,"filename":644,"language":153,"meta":85,"style":85},"language-ts shiki shiki-themes github-light github-light github-dark has-diff","import { createOpenAI } from '@ai-sdk\u002Fopenai'\nimport { convertToModelMessages, stepCountIs, streamText } from 'ai'\nimport { defineEventHandler, defineLazyEventHandler, readBody } from 'h3'\nimport { useRuntimeConfig } from 'nitropack\u002Fruntime'\nimport { z } from 'zod' \u002F\u002F [!code --]\n\nexport default defineLazyEventHandler(() => {\n  const runtimeConfig = useRuntimeConfig()\n\n  const model = createOpenAI({\n    apiKey: runtimeConfig.openAiApiKey,\n  })\n\n  return defineEventHandler(async (event) => {\n    const { messages } = await readBody(event)\n\n    return streamText({\n      model: model('gpt-5-nano'),\n      system: `You are a helpful assistant. You can use the tool to add two numbers together.`,\n      tools: { \u002F\u002F [!code --]\n        addition: tool({ \u002F\u002F [!code --]\n          description: 'Adds two numbers', \u002F\u002F [!code --]\n          inputSchema: z.object({ \u002F\u002F [!code --]\n            a: z.number().describe('The first number'), \u002F\u002F [!code --]\n            b: z.number().describe('The second number'), \u002F\u002F [!code --]\n          }), \u002F\u002F [!code --]\n          execute: ({ a, b }) => ({ \u002F\u002F [!code --]\n            a, \u002F\u002F [!code --]\n            b, \u002F\u002F [!code --]\n            result: a + b \u002F\u002F [!code --]\n          }), \u002F\u002F [!code --]\n        }), \u002F\u002F [!code --]\n      }, \u002F\u002F [!code --]\n      stopWhen: stepCountIs(2),\n      messages: convertToModelMessages(messages),\n    }).toUIMessageStreamResponse()\n  })\n})\n",[87,655,656,668,680,691,703,718,722,738,752,756,770,775,779,783,804,827,831,841,857,867,873,884,896,907,930,949,956,981,988,995,1008,1014,1021,1028,1044,1056,1067,1072],{"__ignoreMap":85},[90,657,658,660,663,665],{"class":92,"line":93},[90,659,161],{"class":160},[90,661,662],{"class":164}," { createOpenAI } ",[90,664,168],{"class":160},[90,666,667],{"class":104}," '@ai-sdk\u002Fopenai'\n",[90,669,670,672,675,677],{"class":92,"line":108},[90,671,161],{"class":160},[90,673,674],{"class":164}," { convertToModelMessages, stepCountIs, streamText } ",[90,676,168],{"class":160},[90,678,679],{"class":104}," 'ai'\n",[90,681,682,684,687,689],{"class":92,"line":186},[90,683,161],{"class":160},[90,685,686],{"class":164}," { defineEventHandler, defineLazyEventHandler, readBody } ",[90,688,168],{"class":160},[90,690,183],{"class":104},[90,692,693,695,698,700],{"class":92,"line":193},[90,694,161],{"class":160},[90,696,697],{"class":164}," { useRuntimeConfig } ",[90,699,168],{"class":160},[90,701,702],{"class":104}," 'nitropack\u002Fruntime'\n",[90,704,708,710,713,715],{"class":705,"line":149},[92,706,707],"diff","remove",[90,709,161],{"class":160},[90,711,712],{"class":164}," { z } ",[90,714,168],{"class":160},[90,716,717],{"class":104}," 'zod'",[90,719,720],{"class":92,"line":150},[90,721,190],{"emptyLinePlaceholder":189},[90,723,724,726,728,731,734,736],{"class":92,"line":151},[90,725,196],{"class":160},[90,727,199],{"class":160},[90,729,730],{"class":96}," defineLazyEventHandler",[90,732,733],{"class":164},"(() ",[90,735,221],{"class":160},[90,737,224],{"class":164},[90,739,740,742,745,747,750],{"class":92,"line":152},[90,741,231],{"class":160},[90,743,744],{"class":100}," runtimeConfig",[90,746,237],{"class":160},[90,748,749],{"class":96}," useRuntimeConfig",[90,751,480],{"class":164},[90,753,754],{"class":92,"line":276},[90,755,190],{"emptyLinePlaceholder":189},[90,757,758,760,763,765,768],{"class":92,"line":409},[90,759,231],{"class":160},[90,761,762],{"class":100}," model",[90,764,237],{"class":160},[90,766,767],{"class":96}," createOpenAI",[90,769,246],{"class":164},[90,771,772],{"class":92,"line":299},[90,773,774],{"class":164},"    apiKey: runtimeConfig.openAiApiKey,\n",[90,776,777],{"class":92,"line":300},[90,778,273],{"class":164},[90,780,781],{"class":92,"line":301},[90,782,190],{"emptyLinePlaceholder":189},[90,784,785,788,790,792,794,796,798,800,802],{"class":92,"line":302},[90,786,787],{"class":160},"  return",[90,789,202],{"class":96},[90,791,205],{"class":164},[90,793,208],{"class":160},[90,795,211],{"class":164},[90,797,215],{"class":214},[90,799,218],{"class":164},[90,801,221],{"class":160},[90,803,224],{"class":164},[90,805,806,809,812,815,818,821,823,825],{"class":92,"line":303},[90,807,808],{"class":160},"    const",[90,810,811],{"class":164}," { ",[90,813,814],{"class":100},"messages",[90,816,817],{"class":164}," } ",[90,819,820],{"class":160},"=",[90,822,533],{"class":160},[90,824,536],{"class":96},[90,826,539],{"class":164},[90,828,829],{"class":92,"line":304},[90,830,190],{"emptyLinePlaceholder":189},[90,832,833,836,839],{"class":92,"line":305},[90,834,835],{"class":160},"    return",[90,837,838],{"class":96}," streamText",[90,840,246],{"class":164},[90,842,843,846,849,851,854],{"class":92,"line":306},[90,844,845],{"class":164},"      model: ",[90,847,848],{"class":96},"model",[90,850,205],{"class":164},[90,852,853],{"class":104},"'gpt-5-nano'",[90,855,856],{"class":164},"),\n",[90,858,859,862,865],{"class":92,"line":307},[90,860,861],{"class":164},"      system: ",[90,863,864],{"class":104},"`You are a helpful assistant. You can use the tool to add two numbers together.`",[90,866,258],{"class":164},[90,868,870],{"class":869,"line":308},[92,706,707],[90,871,872],{"class":164},"      tools: { ",[90,874,876,879,881],{"class":875,"line":309},[92,706,707],[90,877,878],{"class":164},"        addition: ",[90,880,648],{"class":96},[90,882,883],{"class":164},"({ ",[90,885,887,890,893],{"class":886,"line":310},[92,706,707],[90,888,889],{"class":164},"          description: ",[90,891,892],{"class":104},"'Adds two numbers'",[90,894,895],{"class":164},", ",[90,897,899,902,905],{"class":898,"line":311},[92,706,707],[90,900,901],{"class":164},"          inputSchema: z.",[90,903,904],{"class":96},"object",[90,906,883],{"class":164},[90,908,910,913,916,919,922,924,927],{"class":909,"line":312},[92,706,707],[90,911,912],{"class":164},"            a: z.",[90,914,915],{"class":96},"number",[90,917,918],{"class":164},"().",[90,920,921],{"class":96},"describe",[90,923,205],{"class":164},[90,925,926],{"class":104},"'The first number'",[90,928,929],{"class":164},"), ",[90,931,933,936,938,940,942,944,947],{"class":932,"line":561},[92,706,707],[90,934,935],{"class":164},"            b: z.",[90,937,915],{"class":96},[90,939,918],{"class":164},[90,941,921],{"class":96},[90,943,205],{"class":164},[90,945,946],{"class":104},"'The second number'",[90,948,929],{"class":164},[90,950,953],{"class":951,"line":952},[92,706,707],26,[90,954,955],{"class":164},"          }), ",[90,957,960,963,966,968,970,973,976,978],{"class":958,"line":959},[92,706,707],27,[90,961,962],{"class":96},"          execute",[90,964,965],{"class":164},": ({ ",[90,967,14],{"class":214},[90,969,895],{"class":164},[90,971,972],{"class":214},"b",[90,974,975],{"class":164}," }) ",[90,977,221],{"class":160},[90,979,980],{"class":164}," ({ ",[90,982,985],{"class":983,"line":984},[92,706,707],28,[90,986,987],{"class":164},"            a, ",[90,989,992],{"class":990,"line":991},[92,706,707],29,[90,993,994],{"class":164},"            b, ",[90,996,999,1002,1005],{"class":997,"line":998},[92,706,707],30,[90,1000,1001],{"class":164},"            result: a ",[90,1003,1004],{"class":160},"+",[90,1006,1007],{"class":164}," b ",[90,1009,1012],{"class":1010,"line":1011},[92,706,707],31,[90,1013,955],{"class":164},[90,1015,1018],{"class":1016,"line":1017},[92,706,707],32,[90,1019,1020],{"class":164},"        }), ",[90,1022,1025],{"class":1023,"line":1024},[92,706,707],33,[90,1026,1027],{"class":164},"      }, ",[90,1029,1031,1034,1037,1039,1042],{"class":92,"line":1030},34,[90,1032,1033],{"class":164},"      stopWhen: ",[90,1035,1036],{"class":96},"stepCountIs",[90,1038,205],{"class":164},[90,1040,1041],{"class":100},"2",[90,1043,856],{"class":164},[90,1045,1047,1050,1053],{"class":92,"line":1046},35,[90,1048,1049],{"class":164},"      messages: ",[90,1051,1052],{"class":96},"convertToModelMessages",[90,1054,1055],{"class":164},"(messages),\n",[90,1057,1059,1062,1065],{"class":92,"line":1058},36,[90,1060,1061],{"class":164},"    }).",[90,1063,1064],{"class":96},"toUIMessageStreamResponse",[90,1066,480],{"class":164},[90,1068,1070],{"class":92,"line":1069},37,[90,1071,273],{"class":164},[90,1073,1075],{"class":92,"line":1074},38,[90,1076,279],{"class":164},[10,1078,1079,1080,1082],{},"In the ",[87,1081,142],{}," file, register the addition tool with the MCP server.",[79,1084,1087],{"className":146,"code":1085,"filename":142,"highlights":1086,"language":153,"meta":85,"style":85},"import { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { defineEventHandler } from 'h3'\nimport { z } from 'zod'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n\n  server.tool(\n    'addition',\n    'Adds two numbers',\n    {\n      a: z.number().describe('The first number'),\n      b: z.number().describe('The second number')\n    },\n    async (params) => {\n      return {\n        content: [\n          {\n            type: 'text',\n            text: String(params.a + params.b)\n          }\n        ]\n      }\n    }\n  )\n\n  \u002F\u002F ...\n})\n",[186,299,300,301,302,303,304,305,306,307,308,309,310,311,312,561,952,959,984],[87,1088,1089,1099,1109,1121,1125,1147,1161,1169,1175,1179,1183,1194,1202,1210,1216,1234,1253,1259,1276,1284,1290,1296,1307,1324,1330,1336,1342,1348,1354,1358,1364],{"__ignoreMap":85},[90,1090,1091,1093,1095,1097],{"class":92,"line":93},[90,1092,161],{"class":160},[90,1094,165],{"class":164},[90,1096,168],{"class":160},[90,1098,171],{"class":104},[90,1100,1101,1103,1105,1107],{"class":92,"line":108},[90,1102,161],{"class":160},[90,1104,178],{"class":164},[90,1106,168],{"class":160},[90,1108,183],{"class":104},[90,1110,1112,1114,1116,1118],{"class":1111,"line":186},[92,228],[90,1113,161],{"class":160},[90,1115,712],{"class":164},[90,1117,168],{"class":160},[90,1119,1120],{"class":104}," 'zod'\n",[90,1122,1123],{"class":92,"line":193},[90,1124,190],{"emptyLinePlaceholder":189},[90,1126,1127,1129,1131,1133,1135,1137,1139,1141,1143,1145],{"class":92,"line":149},[90,1128,196],{"class":160},[90,1130,199],{"class":160},[90,1132,202],{"class":96},[90,1134,205],{"class":164},[90,1136,208],{"class":160},[90,1138,211],{"class":164},[90,1140,215],{"class":214},[90,1142,218],{"class":164},[90,1144,221],{"class":160},[90,1146,224],{"class":164},[90,1148,1149,1151,1153,1155,1157,1159],{"class":92,"line":150},[90,1150,231],{"class":160},[90,1152,234],{"class":100},[90,1154,237],{"class":160},[90,1156,240],{"class":160},[90,1158,243],{"class":96},[90,1160,246],{"class":164},[90,1162,1163,1165,1167],{"class":92,"line":151},[90,1164,252],{"class":164},[90,1166,255],{"class":104},[90,1168,258],{"class":164},[90,1170,1171,1173],{"class":92,"line":152},[90,1172,264],{"class":164},[90,1174,267],{"class":104},[90,1176,1177],{"class":92,"line":276},[90,1178,273],{"class":164},[90,1180,1181],{"class":92,"line":409},[90,1182,190],{"emptyLinePlaceholder":189},[90,1184,1186,1189,1191],{"class":1185,"line":299},[92,228],[90,1187,1188],{"class":164},"  server.",[90,1190,648],{"class":96},[90,1192,1193],{"class":164},"(\n",[90,1195,1197,1200],{"class":1196,"line":300},[92,228],[90,1198,1199],{"class":104},"    'addition'",[90,1201,258],{"class":164},[90,1203,1205,1208],{"class":1204,"line":301},[92,228],[90,1206,1207],{"class":104},"    'Adds two numbers'",[90,1209,258],{"class":164},[90,1211,1213],{"class":1212,"line":302},[92,228],[90,1214,1215],{"class":164},"    {\n",[90,1217,1219,1222,1224,1226,1228,1230,1232],{"class":1218,"line":303},[92,228],[90,1220,1221],{"class":164},"      a: z.",[90,1223,915],{"class":96},[90,1225,918],{"class":164},[90,1227,921],{"class":96},[90,1229,205],{"class":164},[90,1231,926],{"class":104},[90,1233,856],{"class":164},[90,1235,1237,1240,1242,1244,1246,1248,1250],{"class":1236,"line":304},[92,228],[90,1238,1239],{"class":164},"      b: z.",[90,1241,915],{"class":96},[90,1243,918],{"class":164},[90,1245,921],{"class":96},[90,1247,205],{"class":164},[90,1249,946],{"class":104},[90,1251,1252],{"class":164},")\n",[90,1254,1256],{"class":1255,"line":305},[92,228],[90,1257,1258],{"class":164},"    },\n",[90,1260,1262,1265,1267,1270,1272,1274],{"class":1261,"line":306},[92,228],[90,1263,1264],{"class":160},"    async",[90,1266,211],{"class":164},[90,1268,1269],{"class":214},"params",[90,1271,218],{"class":164},[90,1273,221],{"class":160},[90,1275,224],{"class":164},[90,1277,1279,1282],{"class":1278,"line":307},[92,228],[90,1280,1281],{"class":160},"      return",[90,1283,224],{"class":164},[90,1285,1287],{"class":1286,"line":308},[92,228],[90,1288,1289],{"class":164},"        content: [\n",[90,1291,1293],{"class":1292,"line":309},[92,228],[90,1294,1295],{"class":164},"          {\n",[90,1297,1299,1302,1305],{"class":1298,"line":310},[92,228],[90,1300,1301],{"class":164},"            type: ",[90,1303,1304],{"class":104},"'text'",[90,1306,258],{"class":164},[90,1308,1310,1313,1316,1319,1321],{"class":1309,"line":311},[92,228],[90,1311,1312],{"class":164},"            text: ",[90,1314,1315],{"class":96},"String",[90,1317,1318],{"class":164},"(params.a ",[90,1320,1004],{"class":160},[90,1322,1323],{"class":164}," params.b)\n",[90,1325,1327],{"class":1326,"line":312},[92,228],[90,1328,1329],{"class":164},"          }\n",[90,1331,1333],{"class":1332,"line":561},[92,228],[90,1334,1335],{"class":164},"        ]\n",[90,1337,1339],{"class":1338,"line":952},[92,228],[90,1340,1341],{"class":164},"      }\n",[90,1343,1345],{"class":1344,"line":959},[92,228],[90,1346,1347],{"class":164},"    }\n",[90,1349,1351],{"class":1350,"line":984},[92,228],[90,1352,1353],{"class":164},"  )\n",[90,1355,1356],{"class":92,"line":991},[90,1357,190],{"emptyLinePlaceholder":189},[90,1359,1360],{"class":92,"line":998},[90,1361,1363],{"class":1362},"sCsY4","  \u002F\u002F ...\n",[90,1365,1366],{"class":92,"line":1011},[90,1367,279],{"class":164},[10,1369,1370,1371,1374],{},"Tool registration is deliberately similar to the direct tool we used in Part 1. The implementation and input schema have moved to the MCP server, while its output now follows MCP's standardized ",[87,1372,1373],{},"content"," format. The agent is not connected to this server yet; we will do that in the next article.",[10,1376,1377],{},"Now we can manually use our addition tool:",[25,1379,616,1380,616,1385],{},[618,1381,620,1382,616],{"autoPlay":189,"loop":189,"muted":189,"playsInline":189},[622,1383],{"src":1384,"type":625},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Flisting-and-using-the-addition-tool.mp4",[33,1386,1387],{},"Listing and using the addition tool.",[10,1389,1390],{},"We now have a working MCP server that exposes the addition tool. Next, we will give our agent an MCP client so it can discover and use that tool.",[1392,1393,1394],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":85,"searchDepth":108,"depth":108,"links":1396},[1397],{"id":73,"depth":108,"text":74,"children":1398},[1399,1400],{"id":588,"depth":186,"text":589},{"id":634,"depth":186,"text":635},"b5dafecc-480c-4954-ac35-836d4e71c7a3","2025-10-07","MCP servers are popping up everywhere. Understanding them is key to unlocking the full potential of AI agents.","md",{"branch":1406},"02.mcp-to-provide-additional-capabilities-to-the-ai-agent",null,{},"\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent","---\ncontentId: b5dafecc-480c-4954-ac35-836d4e71c7a3\npart: 2\ntitle: MCP to Provide Additional Capabilities to the AI Agent\ndescription: MCP servers are popping up everywhere. Understanding them is key to unlocking the full potential of AI agents.\ngithub:\n  branch: 02.mcp-to-provide-additional-capabilities-to-the-ai-agent\ndate: 2025-10-07\nseriesSlug: ai-agents-and-mcp-server-teaming-up-for-the-agentic-web\n---\n\nWe built our first AI Agent with an addition tool. In this article, we will move that tool into an [MCP server](https:\u002F\u002Fmodelcontextprotocol.io\u002Fdocs\u002Fgetting-started\u002Fintro), where it can be discovered and used through a standard protocol.\n\nA quick reminder about MCP: MCP is an open-source standard for connecting AI applications to external systems. An MCP server provides tools, while an MCP client connects to that server and calls its tools on the agent's behalf. In this series, our AI application contains the agent and its MCP client; the MCP server exposes the capabilities the agent needs. Visually, it looks like this:\n\n![AI application interacting with the real world through MCP.](\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Fmcp.webp)\n\nYou might wonder why we need an MCP server. We do not strictly need one for this small addition tool: a direct tool is simpler when the capability belongs only to one tightly coupled application. MCP becomes useful when a capability should be shared, independently deployed, or consumed by compatible clients.\n\n1. **Support compatible clients**: By providing MCP, you allow AI applications and coding tools that support the protocol to use your capabilities. For example, a [component-library MCP server](https:\u002F\u002Fui.nuxt.com\u002Fdocs\u002Fgetting-started\u002Fai\u002Fmcp) can make its documentation and tools available in a code editor.\n2. **Use external MCP servers**: Your agent can also connect to an MCP server you did not create to integrate with an existing system or third-party capability.\n3. **Decouple capabilities**: The agent only needs to know a tool's name, description, input, and output. The MCP server owns its implementation and can evolve independently.\n\nFor this series, MCP gives us a clear boundary between the agent and the capabilities it can use.\n\n## Building the MCP server\n\nWithin our Nitro application, we can create a new route for the MCP server.\n\n```bash [terminal]\nmkdir -p server\u002Froutes\ntouch server\u002Froutes\u002Fmcp.ts\n```\n\nThen, we have to install the MCP SDK:\n\n```bash [terminal]\npnpm add @modelcontextprotocol\u002Fsdk@^1.29.0\n```\n\nThis is the official TypeScript SDK for building MCP servers.\n\nNow, we can create our MCP server within the `server\u002Froutes\u002Fmcp.ts` file:\n\n```ts [server\u002Froutes\u002Fmcp.ts] {5-8}\nimport { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { defineEventHandler } from 'h3'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n})\n```\n\nWe now have an MCP server object, but it cannot receive requests yet. MCP separates the server, which defines the protocol capabilities and tools, from the transport, which carries requests and responses. In our case, the Nitro route will host a Streamable HTTP transport so an MCP client can reach the server over HTTP.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nStreamable HTTP is useful here because it allows a remotely hosted MCP server to communicate through regular HTTP requests and responses.\n::\n\nFortunately, the MCP SDK provides everything we need to add an HTTP transport layer.\n\n```ts [Example] {3,11-24}\nimport { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002FstreamableHttp.js'\nimport { defineEventHandler, readBody } from 'h3'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n\n  const transport = new StreamableHTTPServerTransport({\n    sessionIdGenerator: undefined\n  })\n\n  event.node.res.on('close', () => {\n    transport.close()\n    server.close()\n  })\n\n  await server.connect(transport)\n\n  const body = await readBody(event)\n\n  await transport.handleRequest(event.node.req, event.node.res, body)\n})\n```\n\nWith `server.connect(transport)`, we attach the server to the HTTP transport. With `transport.handleRequest(event.node.req, event.node.res, body)`, we pass the incoming request to that transport, which sends the response back to the client. This example creates a stateless transport for each request, so `sessionIdGenerator: undefined` disables session IDs. When the response ends or terminates prematurely, we close the transport and server to free their resources.\n\nThe request body is important because tool calls can include input parameters.\n\nWith this setup, we can now try the MCP.\n\n### Trying the MCP\n\nTo try the MCP, we can use the official MCP Inspector:\n\n```bash [terminal]\nnpx @modelcontextprotocol\u002Finspector@latest\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nUse the inspector to verify an MCP server before connecting it to an AI application. A model may decide not to call a particular tool, while the inspector lets you test the protocol and tools directly.\n::\n\nThen, we can enter the MCP URL and ping the server to make sure it's working.\n\n\u003Cfigure>\n  \u003Cvideo autoplay loop muted playsinline>\n    \u003Csource src=\"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Fpinging-server.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>Pinging the MCP server.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\nThe server is now reachable through its HTTP transport.\n\n### Adding a tool\n\nNow that we have a working MCP server, we can move our addition tool from the AI Agent to the MCP server.\n\nWithin the `server\u002Fapi\u002Fchat.ts` file, remove `tool` from the AI SDK import, remove the Zod import, and delete the addition tool registration:\n\n```ts [server\u002Fapi\u002Fchat.ts]\nimport { createOpenAI } from '@ai-sdk\u002Fopenai'\nimport { convertToModelMessages, stepCountIs, streamText } from 'ai'\nimport { defineEventHandler, defineLazyEventHandler, readBody } from 'h3'\nimport { useRuntimeConfig } from 'nitropack\u002Fruntime'\nimport { z } from 'zod' \u002F\u002F [!code --]\n\nexport default defineLazyEventHandler(() => {\n  const runtimeConfig = useRuntimeConfig()\n\n  const model = createOpenAI({\n    apiKey: runtimeConfig.openAiApiKey,\n  })\n\n  return defineEventHandler(async (event) => {\n    const { messages } = await readBody(event)\n\n    return streamText({\n      model: model('gpt-5-nano'),\n      system: `You are a helpful assistant. You can use the tool to add two numbers together.`,\n      tools: { \u002F\u002F [!code --]\n        addition: tool({ \u002F\u002F [!code --]\n          description: 'Adds two numbers', \u002F\u002F [!code --]\n          inputSchema: z.object({ \u002F\u002F [!code --]\n            a: z.number().describe('The first number'), \u002F\u002F [!code --]\n            b: z.number().describe('The second number'), \u002F\u002F [!code --]\n          }), \u002F\u002F [!code --]\n          execute: ({ a, b }) => ({ \u002F\u002F [!code --]\n            a, \u002F\u002F [!code --]\n            b, \u002F\u002F [!code --]\n            result: a + b \u002F\u002F [!code --]\n          }), \u002F\u002F [!code --]\n        }), \u002F\u002F [!code --]\n      }, \u002F\u002F [!code --]\n      stopWhen: stepCountIs(2),\n      messages: convertToModelMessages(messages),\n    }).toUIMessageStreamResponse()\n  })\n})\n```\n\nIn the `server\u002Froutes\u002Fmcp.ts` file, register the addition tool with the MCP server.\n\n```ts [server\u002Froutes\u002Fmcp.ts] {3,11-28}\nimport { McpServer } from '@modelcontextprotocol\u002Fsdk\u002Fserver\u002Fmcp.js'\nimport { defineEventHandler } from 'h3'\nimport { z } from 'zod'\n\nexport default defineEventHandler(async (event) => {\n  const server = new McpServer({\n    name: 'ai-agent',\n    version: '1.0.0'\n  })\n\n  server.tool(\n    'addition',\n    'Adds two numbers',\n    {\n      a: z.number().describe('The first number'),\n      b: z.number().describe('The second number')\n    },\n    async (params) => {\n      return {\n        content: [\n          {\n            type: 'text',\n            text: String(params.a + params.b)\n          }\n        ]\n      }\n    }\n  )\n\n  \u002F\u002F ...\n})\n```\n\nTool registration is deliberately similar to the direct tool we used in Part 1. The implementation and input schema have moved to the MCP server, while its output now follows MCP's standardized `content` format. The agent is not connected to this server yet; we will do that in the next article.\n\nNow we can manually use our addition tool:\n\n\u003Cfigure>\n  \u003Cvideo autoplay loop muted playsinline>\n    \u003Csource src=\"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent\u002Flisting-and-using-the-addition-tool.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>Listing and using the addition tool.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\nWe now have a working MCP server that exposes the addition tool. Next, we will give our agent an MCP client so it can discover and use that tool.\n",{"title":5,"description":1403},"ai-agents-and-mcp-server-teaming-up-for-the-agentic-web",{"loc":1409,"images":1414},[1415],{"loc":31},"series\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent","VHbLYREIl8c32VZJ7hVrpDT4ZPCaadoFZAxQJbDlchA",{"overview":1419,"chapters":1525},{"id":1420,"title":1421,"body":1422,"contentId":1504,"date":1402,"description":1505,"extension":1404,"github":1506,"meetTheInstructor":1509,"meta":1510,"navigation":189,"part":1407,"path":1511,"rawbody":1512,"robots":1407,"schemaOrg":1407,"seo":1513,"seriesSlug":1412,"sitemap":1514,"stem":1515,"subtitle":1516,"topics":1517,"__hash__":1524},"series\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web.md","AI Agents and MCP Server: Teaming Up for the Agentic Web",{"type":7,"value":1423,"toc":1501},[1424,1427,1430,1438,1441,1444,1447,1478,1481,1491,1495],[10,1425,1426],{},"Hey 👋,",[10,1428,1429],{},"For months, I've been exploring AI and the latest innovations. I've been fascinated by the idea of chatting with my website, literally chatting with it through an interface like the one you use to talk to a friend on your phone. That idea led me to create AI Agents that can interact with my website and provide users with high-quality, up-to-date, context-aware information.",[10,1431,1432,1433,1437],{},"This series is not about the exact implementation details of my AI Agent. I have already written two articles about that. The first covers ",[14,1434,1436],{"href":1435},"\u002Fposts\u002Fai-agents-will-deeply-transform-our-experience-with-the-web","the rise of AI Agents"," and their potential impact on the web. The second covers the technical implementation of my AI Agent.",[10,1439,1440],{},"Instead, this series focuses on the foundational concepts you need to get started with your own AI Agent and connect it to an MCP server for additional capabilities.",[10,1442,1443],{},"We will not build anything particularly elaborate because the agentic web is still at an early stage. As I mentioned in my article about the rise of AI Agents, everything remains to be built. There are no established patterns or definitive ways of working yet. For now, the best approach is to build, experiment, evaluate, and iterate.",[10,1445,1446],{},"Throughout this series, we will:",[39,1448,1449,1455,1460,1466,1472],{},[42,1450,1451,1454],{},[45,1452,1453],{},"Building an AI Agent Made Easy Thanks to the AI SDK",": Using the AI SDK, we'll build our first AI Agent and understand what makes it different from a traditional AI.",[42,1456,1457,1459],{},[45,1458,5],{},": With the official MCP SDK, we'll create an MCP server with a simple tool and interact with it.",[42,1461,1462,1465],{},[45,1463,1464],{},"Pairing AI Agents with MCP to Make the Outside World Accessible",": An AI Agent needs tools, so we'll connect the Agent to the MCP server and let it interact with the outside world.",[42,1467,1468,1471],{},[45,1469,1470],{},"A Powerful AI Application Made with Nitro and Nuxt UI",": We'll build a user interface that makes it easy to interact with our AI Agent.",[42,1473,1474,1477],{},[45,1475,1476],{},"Deploying Our AI Agent to the World Using Cloudflare",": Finally, we'll deploy the AI application and MCP server on Cloudflare. I chose this platform, but you can deploy them wherever you prefer.",[10,1479,1480],{},"By the end, you will have a complete chat interface for talking to your AI Agent, along with all the pieces you need to keep experimenting.",[25,1482,616,1483,616,1488],{},[618,1484,620,1485,616],{"autoPlay":189,"loop":189,"muted":189,"playsInline":189},[622,1486],{"src":1487,"type":625},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fai-application.mp4",[33,1489,1490],{},"Our final AI application.",[71,1492,1494],{"id":1493},"chapters","Chapters",[1496,1497],"series-chapters-list",{"className":1498},[1499,1500],"mx-auto","max-w-5xl",{"title":85,"searchDepth":108,"depth":108,"links":1502},[1503],{"id":1493,"depth":108,"text":1494},"76bfa6ec-7e25-4813-a0ae-f4e956e510df","Build an AI application, understand how AI Agents work, and discover how pairing them with an MCP server expands what they can do.",{"name":1507,"repository":1508},"AI Agents and MCP","barbapapazes\u002Fai-agent","For months, I've been fascinated by AI and its potential. I struggled to find the right resources to understand how AI Agents work. After researching and experimenting, I started to grasp the core concepts and I'm excited to share what I learned with you.",{},"\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web","---\ncontentId: 76bfa6ec-7e25-4813-a0ae-f4e956e510df\ntitle: \"AI Agents and MCP Server: Teaming Up for the Agentic Web\"\nsubtitle: Explore the future of the web by building an AI application\ndescription: Build an AI application, understand how AI Agents work, and discover how pairing them with an MCP server expands what they can do.\ndate: 2025-10-07\ntopics:\n  - ai-agents\n  - ai\n  - mcp\n  - agentic-web\n  - nuxt\n  - nuxt-ui\ngithub:\n  name: AI Agents and MCP\n  repository: barbapapazes\u002Fai-agent\nmeetTheInstructor: For months, I've been fascinated by AI and its potential. I struggled to find the right resources to understand how AI Agents work. After researching and experimenting, I started to grasp the core concepts and I'm excited to share what I learned with you.\nseriesSlug: ai-agents-and-mcp-server-teaming-up-for-the-agentic-web\n---\n\nHey 👋,\n\nFor months, I've been exploring AI and the latest innovations. I've been fascinated by the idea of chatting with my website, literally chatting with it through an interface like the one you use to talk to a friend on your phone. That idea led me to create AI Agents that can interact with my website and provide users with high-quality, up-to-date, context-aware information.\n\nThis series is not about the exact implementation details of my AI Agent. I have already written two articles about that. The first covers [the rise of AI Agents](\u002Fposts\u002Fai-agents-will-deeply-transform-our-experience-with-the-web) and their potential impact on the web. The second covers the technical implementation of my AI Agent.\n\nInstead, this series focuses on the foundational concepts you need to get started with your own AI Agent and connect it to an MCP server for additional capabilities.\n\nWe will not build anything particularly elaborate because the agentic web is still at an early stage. As I mentioned in my article about the rise of AI Agents, everything remains to be built. There are no established patterns or definitive ways of working yet. For now, the best approach is to build, experiment, evaluate, and iterate.\n\nThroughout this series, we will:\n\n1. **Building an AI Agent Made Easy Thanks to the AI SDK**: Using the AI SDK, we'll build our first AI Agent and understand what makes it different from a traditional AI.\n2. **MCP to Provide Additional Capabilities to the AI Agent**: With the official MCP SDK, we'll create an MCP server with a simple tool and interact with it.\n3. **Pairing AI Agents with MCP to Make the Outside World Accessible**: An AI Agent needs tools, so we'll connect the Agent to the MCP server and let it interact with the outside world.\n4. **A Powerful AI Application Made with Nitro and Nuxt UI**: We'll build a user interface that makes it easy to interact with our AI Agent.\n5. **Deploying Our AI Agent to the World Using Cloudflare**: Finally, we'll deploy the AI application and MCP server on Cloudflare. I chose this platform, but you can deploy them wherever you prefer.\n\nBy the end, you will have a complete chat interface for talking to your AI Agent, along with all the pieces you need to keep experimenting.\n\n\u003Cfigure>\n  \u003Cvideo autoplay loop muted playsinline>\n    \u003Csource src=\"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fai-application.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>Our final AI application.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":1421,"description":1505},{"loc":1511},"series\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web","Explore the future of the web by building an AI application",[1518,1519,1520,1521,1522,1523],"ai-agents","ai","mcp","agentic-web","nuxt","nuxt-ui","3fbdjQUyeN3fzx5NIJ-SVb3udixzleWLpFXsAeV6Tkw",[1526,1532,1534,1541,1547],{"contentId":1527,"title":1453,"description":1528,"path":1529,"part":93,"github":1530,"topics":1407},"9ffbf543-f6d5-45d3-ae35-eb1bfb26843e","AI agents can be mysterious, but they are not as complicated as they seem. Let's prove it with in-depth explanations and examples.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk",{"branch":1531},"01.building-an-ai-agent-made-easy-thanks-to-the-ai-sdk",{"contentId":1401,"title":5,"description":1403,"path":1409,"part":108,"github":1533,"topics":1407},{"branch":1406},{"contentId":1535,"title":1536,"description":1537,"path":1538,"part":186,"github":1539,"topics":1407},"4c18ff8d-db49-4197-96f9-7ec16756e9cd","Pair AI Agents with MCP to Access the Outside World","AI agents with custom tools are powerful. Connecting an MCP server to an agent unlocks another level of capability.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fpair-ai-agents-with-mcp-to-access-the-outside-world",{"branch":1540},"03.pairing-ai-agents-with-mcp-to-make-outside-world-accessible",{"contentId":1542,"title":1470,"description":1543,"path":1544,"part":193,"github":1545,"topics":1407},"19f0acd2-037f-4538-9d69-cbb86a0bea64","Having an AI agent is a good start, but integrating it into an application makes all the difference. Nuxt UI makes that easy.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fa-powerful-ai-application-made-with-nitro-and-nuxt-ui",{"branch":1546},"04.a-powerful-ai-application-made-with-nitro-and-nuxt-ui",{"contentId":1548,"title":1476,"description":1549,"path":1550,"part":149,"github":1551,"topics":1407},"d06af237-adf9-480b-9fd6-51624834efdd","Deploy the AI application and its MCP server on Cloudflare so people can use its capabilities online from any agent.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fdeploying-our-ai-agent-to-the-world-using-cloudflare",{"branch":1552},"05.deploying-our-ai-agent-to-the-world-using-cloudflare",1795016691308]