[{"data":1,"prerenderedAt":1846},["ShallowReactive",2],{"series-\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk":3,"series-context-\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web":1711},{"id":4,"title":5,"body":6,"contentId":1694,"date":1695,"description":1696,"extension":1697,"github":1698,"meetTheInstructor":1700,"meta":1701,"navigation":160,"part":143,"path":1702,"rawbody":1703,"robots":1700,"schemaOrg":1700,"seo":1704,"seriesSlug":1705,"sitemap":1706,"stem":1709,"subtitle":1700,"topics":1700,"__hash__":1710},"series\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk.md","Building an AI Agent Made Easy Thanks to the AI SDK",{"type":7,"value":8,"toc":1683},"minimark",[9,13,16,19,56,61,64,76,84,87,104,107,118,122,125,128,302,308,313,317,320,329,332,343,346,355,360,363,392,399,412,416,419,422,440,449,466,477,480,536,539,543,546,549,570,577,830,833,840,867,874,881,935,956,959,966,1065,1072,1087,1090,1094,1097,1100,1114,1121,1321,1324,1372,1375,1455,1465,1468,1471,1482,1485,1489,1492,1567,1574,1585,1588,1666,1676,1679],[10,11,12],"p",{},"Before going any further, what's an AI Agent? Clarifying that concept will make the rest of the series easier to follow.",[10,14,15],{},"An AI Agent is software that uses a model to work toward a user's goal. It can interpret a natural-language request, decide whether it needs an external capability, use that capability, and continue until it can provide a useful result. This makes interactions with software more natural: the user describes the outcome they want instead of manually coordinating every step.",[10,17,18],{},"Throughout this series, we will use five terms consistently:",[20,21,22,31,37,44,50],"ul",{},[23,24,25,26,30],"li",{},"An ",[27,28,29],"strong",{},"AI application"," is the chat product a person uses.",[23,32,25,33,36],{},[27,34,35],{},"AI agent"," is the server-side orchestration that gives the model access to tools and lets it continue after using them.",[23,38,39,40,43],{},"A ",[27,41,42],{},"tool"," is a function the agent can ask its host application to run.",[23,45,25,46,49],{},[27,47,48],{},"MCP server"," exposes tools through the Model Context Protocol.",[23,51,25,52,55],{},[27,53,54],{},"MCP client"," connects the agent to an MCP server.",[57,58,60],"h2",{"id":59},"what-the-model-can-do","What the Model Can Do",[10,62,63],{},"To keep the series focused, we'll work with text-based LLMs. In this example, the model can:",[65,66,67,70,73],"ol",{},[23,68,69],{},"Generate text from the messages it receives.",[23,71,72],{},"Use the available context to decide what to say or do next.",[23,74,75],{},"Request a tool call so the host application can perform an action outside the model.",[77,78,81],"callout",{"color":79,"icon":80},"info","i-ph-info-duotone",[10,82,83],{},"Depending on the provider, there may be additional functionalities available, like built-in tools or MCP tools. Ultimately, everything is considered a tool, whether it's a built-in function, an external API via MCP, or a custom tool.",[10,85,86],{},"When you interact with an AI, the model may use one or more of these capabilities. Its internal reasoning is model- and provider-specific, and it may not be exposed to your application. A model can also produce text before, between, or after tool calls.",[10,88,89,90,97,98,103],{},"The important part for us is this: after a tool call completes, the result must be given back to the model so it can decide what to do next. The latest models can ",[91,92,96],"a",{"href":93,"rel":94},"https:\u002F\u002Fopenai.com\u002Findex\u002Fintroducing-gpt-5-for-developers\u002F#:~:text=making%20many%20tool%20calls%20in%20sequence%20or%20in%20parallel",[95],"nofollow","call multiple tools",", including in sequence or in parallel, and can ",[91,99,102],{"href":100,"rel":101},"https:\u002F\u002Fopenai.com\u002Findex\u002Fintroducing-gpt-5-for-developers\u002F#:~:text=GPT%E2%80%915%20can%20also%20output%20preamble%20messages%20before%20and%20between%20tool%20calls%20to%20update%20users%20on%20progress%20during%20longer%20agentic%20tasks.",[95],"generate progress updates around tool calls",".",[10,105,106],{},"Without orchestration, a tool call may be the last event your application handles. The user would see that the calculation happened but would not receive the model's final answer. Our agent will handle that follow-up automatically.",[77,108,109],{"color":79,"icon":80},[10,110,111,112,117],{},"It's important to note that the AI does not run custom tools directly. It asks the client, via a dedicated response, to call the tool on its behalf. That's why defining tools is often just defining a JSON schema. I recommend reading the ",[91,113,116],{"href":114,"rel":115},"https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ffunction-calling#the-tool-calling-flow",[95],"tool calling flow"," in the OpenAI documentation.",[57,119,121],{"id":120},"continuing-after-a-tool-call","Continuing after a tool call",[10,123,124],{},"To solve this problem, the application needs a bounded loop. When the model asks for a tool, the application runs it, adds the result to the conversation, and lets the model continue.",[10,126,127],{},"In simplified pseudo-code, that looks like this:",[129,130,136],"pre",{"className":131,"code":132,"filename":133,"language":134,"meta":135,"style":135},"language-js shiki shiki-themes github-light github-light github-dark","messages = [userInput]\n\nwhile (hasStepsRemaining) {\n  response = AI.ask(messages)\n  messages.push(response)\n\n  if (response.hasReasoning()) {\n    showProgress(response.reasoning)\n  }\n\n  if (response.isText()) {\n    break\n  }\n\n  toolResult = runTool(response.toolCall)\n  messages.push(toolResult)\n}\n","Example","js","",[137,138,139,155,162,171,192,204,209,224,233,239,244,256,262,267,272,286,296],"code",{"__ignoreMap":135},[140,141,144,148,152],"span",{"class":142,"line":143},"line",1,[140,145,147],{"class":146},"sxrX7","messages ",[140,149,151],{"class":150},"s8jYJ","=",[140,153,154],{"class":146}," [userInput]\n",[140,156,158],{"class":142,"line":157},2,[140,159,161],{"emptyLinePlaceholder":160},true,"\n",[140,163,165,168],{"class":142,"line":164},3,[140,166,167],{"class":150},"while",[140,169,170],{"class":146}," (hasStepsRemaining) {\n",[140,172,174,177,179,183,185,189],{"class":142,"line":173},4,[140,175,176],{"class":146},"  response ",[140,178,151],{"class":150},[140,180,182],{"class":181},"sBjJW"," AI",[140,184,103],{"class":146},[140,186,188],{"class":187},"snPdu","ask",[140,190,191],{"class":146},"(messages)\n",[140,193,195,198,201],{"class":142,"line":194},5,[140,196,197],{"class":146},"  messages.",[140,199,200],{"class":187},"push",[140,202,203],{"class":146},"(response)\n",[140,205,207],{"class":142,"line":206},6,[140,208,161],{"emptyLinePlaceholder":160},[140,210,212,215,218,221],{"class":142,"line":211},7,[140,213,214],{"class":150},"  if",[140,216,217],{"class":146}," (response.",[140,219,220],{"class":187},"hasReasoning",[140,222,223],{"class":146},"()) {\n",[140,225,227,230],{"class":142,"line":226},8,[140,228,229],{"class":187},"    showProgress",[140,231,232],{"class":146},"(response.reasoning)\n",[140,234,236],{"class":142,"line":235},9,[140,237,238],{"class":146},"  }\n",[140,240,242],{"class":142,"line":241},10,[140,243,161],{"emptyLinePlaceholder":160},[140,245,247,249,251,254],{"class":142,"line":246},11,[140,248,214],{"class":150},[140,250,217],{"class":146},[140,252,253],{"class":187},"isText",[140,255,223],{"class":146},[140,257,259],{"class":142,"line":258},12,[140,260,261],{"class":150},"    break\n",[140,263,265],{"class":142,"line":264},13,[140,266,238],{"class":146},[140,268,270],{"class":142,"line":269},14,[140,271,161],{"emptyLinePlaceholder":160},[140,273,275,278,280,283],{"class":142,"line":274},15,[140,276,277],{"class":146},"  toolResult ",[140,279,151],{"class":150},[140,281,282],{"class":187}," runTool",[140,284,285],{"class":146},"(response.toolCall)\n",[140,287,289,291,293],{"class":142,"line":288},16,[140,290,197],{"class":146},[140,292,200],{"class":187},[140,294,295],{"class":146},"(toolResult)\n",[140,297,299],{"class":142,"line":298},17,[140,300,301],{"class":146},"}\n",[10,303,304,307],{},[137,305,306],{},"response.hasReasoning()"," is optional: whether an application receives reasoning depends on the model and provider. When it is available, it can be shown as progress, but the full response must still be added to the conversation so the next step has the tool call and any associated model context. This loop is not the definition of an AI Agent. It is the mechanism that lets an agent work through a task across multiple model and tool steps.",[77,309,310],{"color":79,"icon":80},[10,311,312],{},"To avoid an infinite loop, define a maximum number of iterations.",[57,314,316],{"id":315},"our-agent","Our agent",[10,318,319],{},"I think we're ready to start building our AI Agent.",[10,321,322,323,328],{},"For this series, we will use the ",[91,324,327],{"href":325,"rel":326},"https:\u002F\u002Fai-sdk.dev",[95],"AI SDK",". We could have used a provider SDK such as OpenAI's or Anthropic's, but the AI SDK gives us a higher-level interface while keeping the provider interchangeable.",[10,330,331],{},"To make sure we're all on the same page, here's a quick overview of the infrastructure we're building.",[333,334,335,340],"figure",{},[336,337],"img",{"alt":338,"src":339},"AI Agent Infrastructure.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fai-agent-infrastructure.webp",[341,342,338],"figcaption",{},[10,344,345],{},"For this part, we'll focus on the server-side implementation and the communication with the provider.",[10,347,348,349,354],{},"To do so, we'll use ",[91,350,353],{"href":351,"rel":352},"https:\u002F\u002Fnitro.build\u002F",[95],"Nitro",", but you can use any JS backend framework of your choice.",[356,357,359],"h3",{"id":358},"installation","Installation",[10,361,362],{},"First, create a new Nitro project:",[129,364,369],{"className":365,"code":366,"filename":367,"language":368,"meta":135,"style":135},"language-bash shiki shiki-themes github-light github-light github-dark","pnpm dlx giget@latest nitro ai-agent --install\n","terminal","bash",[137,370,371],{"__ignoreMap":135},[140,372,373,376,380,383,386,389],{"class":142,"line":143},[140,374,375],{"class":187},"pnpm",[140,377,379],{"class":378},"sIIMD"," dlx",[140,381,382],{"class":378}," giget@latest",[140,384,385],{"class":378}," nitro",[140,387,388],{"class":378}," ai-agent",[140,390,391],{"class":181}," --install\n",[10,393,394,395,398],{},"Then remove the ",[137,396,397],{},"server\u002Froutes\u002Findex.ts"," file, which we won't need:",[129,400,402],{"className":365,"code":401,"filename":397,"language":368,"meta":135,"style":135},"rm server\u002Froutes\u002Findex.ts\n",[137,403,404],{"__ignoreMap":135},[140,405,406,409],{"class":142,"line":143},[140,407,408],{"class":187},"rm",[140,410,411],{"class":378}," server\u002Froutes\u002Findex.ts\n",[356,413,415],{"id":414},"starting-with-the-ai-sdk","Starting with the AI SDK",[10,417,418],{},"Now that our backend is set up, we can start working with the AI SDK.",[10,420,421],{},"Install the SDK:",[129,423,425],{"className":365,"code":424,"filename":367,"language":368,"meta":135,"style":135},"pnpm add ai @ai-sdk\u002Fopenai\n",[137,426,427],{"__ignoreMap":135},[140,428,429,431,434,437],{"class":142,"line":143},[140,430,375],{"class":187},[140,432,433],{"class":378}," add",[140,435,436],{"class":378}," ai",[140,438,439],{"class":378}," @ai-sdk\u002Fopenai\n",[10,441,442,443,448],{},"We also install the OpenAI adapter to communicate with the OpenAI API, but you can use ",[91,444,447],{"href":445,"rel":446},"https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Ffoundations\u002Fproviders-and-models#providers-and-models",[95],"any other adapter"," you prefer.",[10,450,451,452,457,458,461,462,465],{},"To communicate with OpenAI, set up an API key. You can obtain one by creating an account on the ",[91,453,456],{"href":454,"rel":455},"https:\u002F\u002Fplatform.openai.com\u002Fsignup",[95],"OpenAI website",". Then set the ",[137,459,460],{},"OPENAI_API_KEY"," environment variable in your ",[137,463,464],{},".env"," file:",[129,467,471],{"className":468,"code":469,"filename":133,"language":470,"meta":135,"style":135},"language-ini shiki shiki-themes github-light github-light github-dark","NITRO_OPEN_AI_API_KEY=\n","ini",[137,472,473],{"__ignoreMap":135},[140,474,475],{"class":142,"line":143},[140,476,469],{},[10,478,479],{},"Finally, create a runtime variable within the Nitro configuration:",[129,481,486],{"className":482,"code":483,"filename":133,"highlights":484,"language":485,"meta":135,"style":135},"language-ts shiki shiki-themes github-light github-light github-dark","export default defineNitroConfig({\n  runtimeConfig: {\n    openAiApiKey: '',\n  },\n  \u002F\u002F ...\n})\n",[164],"ts",[137,487,488,502,507,520,525,531],{"__ignoreMap":135},[140,489,490,493,496,499],{"class":142,"line":143},[140,491,492],{"class":150},"export",[140,494,495],{"class":150}," default",[140,497,498],{"class":187}," defineNitroConfig",[140,500,501],{"class":146},"({\n",[140,503,504],{"class":142,"line":157},[140,505,506],{"class":146},"  runtimeConfig: {\n",[140,508,511,514,517],{"class":509,"line":164},[142,510],"highlight",[140,512,513],{"class":146},"    openAiApiKey: ",[140,515,516],{"class":378},"''",[140,518,519],{"class":146},",\n",[140,521,522],{"class":142,"line":173},[140,523,524],{"class":146},"  },\n",[140,526,527],{"class":142,"line":194},[140,528,530],{"class":529},"sCsY4","  \u002F\u002F ...\n",[140,532,533],{"class":142,"line":206},[140,534,535],{"class":146},"})\n",[10,537,538],{},"Now we're ready to start building our AI Agent.",[356,540,542],{"id":541},"streaming-some-text","Streaming some text",[10,544,545],{},"The first step is to make sure our AI Agent can generate text based on user input. This may be more challenging than it seems, but the AI SDK provides a simple way to achieve it.",[10,547,548],{},"Create a new endpoint in the Nitro server that will receive the user query and return the AI-generated response:",[129,550,552],{"className":365,"code":551,"filename":367,"language":368,"meta":135,"style":135},"mkdir server\u002Fapi\ntouch server\u002Fapi\u002Fchat.ts\n",[137,553,554,562],{"__ignoreMap":135},[140,555,556,559],{"class":142,"line":143},[140,557,558],{"class":187},"mkdir",[140,560,561],{"class":378}," server\u002Fapi\n",[140,563,564,567],{"class":142,"line":157},[140,565,566],{"class":187},"touch",[140,568,569],{"class":378}," server\u002Fapi\u002Fchat.ts\n",[10,571,572,573,576],{},"Then create the endpoint in ",[137,574,575],{},"server\u002Fapi\u002Fchat.ts",":",[129,578,580],{"className":482,"code":579,"filename":575,"language":485,"meta":135,"style":135},"import { createOpenAI } from '@ai-sdk\u002Fopenai'\nimport { convertToModelMessages, streamText } from 'ai'\nimport { defineEventHandler, defineLazyEventHandler, readBody } from 'h3'\nimport { useRuntimeConfig } from 'nitropack\u002Fruntime'\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.`,\n      messages: convertToModelMessages(messages),\n    }).toUIMessageStreamResponse()\n  })\n})\n",[137,581,582,596,608,620,632,636,654,671,675,689,694,699,703,731,756,760,770,786,797,809,820,825],{"__ignoreMap":135},[140,583,584,587,590,593],{"class":142,"line":143},[140,585,586],{"class":150},"import",[140,588,589],{"class":146}," { createOpenAI } ",[140,591,592],{"class":150},"from",[140,594,595],{"class":378}," '@ai-sdk\u002Fopenai'\n",[140,597,598,600,603,605],{"class":142,"line":157},[140,599,586],{"class":150},[140,601,602],{"class":146}," { convertToModelMessages, streamText } ",[140,604,592],{"class":150},[140,606,607],{"class":378}," 'ai'\n",[140,609,610,612,615,617],{"class":142,"line":164},[140,611,586],{"class":150},[140,613,614],{"class":146}," { defineEventHandler, defineLazyEventHandler, readBody } ",[140,616,592],{"class":150},[140,618,619],{"class":378}," 'h3'\n",[140,621,622,624,627,629],{"class":142,"line":173},[140,623,586],{"class":150},[140,625,626],{"class":146}," { useRuntimeConfig } ",[140,628,592],{"class":150},[140,630,631],{"class":378}," 'nitropack\u002Fruntime'\n",[140,633,634],{"class":142,"line":194},[140,635,161],{"emptyLinePlaceholder":160},[140,637,638,640,642,645,648,651],{"class":142,"line":206},[140,639,492],{"class":150},[140,641,495],{"class":150},[140,643,644],{"class":187}," defineLazyEventHandler",[140,646,647],{"class":146},"(() ",[140,649,650],{"class":150},"=>",[140,652,653],{"class":146}," {\n",[140,655,656,659,662,665,668],{"class":142,"line":211},[140,657,658],{"class":150},"  const",[140,660,661],{"class":181}," runtimeConfig",[140,663,664],{"class":150}," =",[140,666,667],{"class":187}," useRuntimeConfig",[140,669,670],{"class":146},"()\n",[140,672,673],{"class":142,"line":226},[140,674,161],{"emptyLinePlaceholder":160},[140,676,677,679,682,684,687],{"class":142,"line":235},[140,678,658],{"class":150},[140,680,681],{"class":181}," model",[140,683,664],{"class":150},[140,685,686],{"class":187}," createOpenAI",[140,688,501],{"class":146},[140,690,691],{"class":142,"line":241},[140,692,693],{"class":146},"    apiKey: runtimeConfig.openAiApiKey,\n",[140,695,696],{"class":142,"line":246},[140,697,698],{"class":146},"  })\n",[140,700,701],{"class":142,"line":258},[140,702,161],{"emptyLinePlaceholder":160},[140,704,705,708,711,714,717,720,724,727,729],{"class":142,"line":264},[140,706,707],{"class":150},"  return",[140,709,710],{"class":187}," defineEventHandler",[140,712,713],{"class":146},"(",[140,715,716],{"class":150},"async",[140,718,719],{"class":146}," (",[140,721,723],{"class":722},"sP4rz","event",[140,725,726],{"class":146},") ",[140,728,650],{"class":150},[140,730,653],{"class":146},[140,732,733,736,739,742,745,747,750,753],{"class":142,"line":269},[140,734,735],{"class":150},"    const",[140,737,738],{"class":146}," { ",[140,740,741],{"class":181},"messages",[140,743,744],{"class":146}," } ",[140,746,151],{"class":150},[140,748,749],{"class":150}," await",[140,751,752],{"class":187}," readBody",[140,754,755],{"class":146},"(event)\n",[140,757,758],{"class":142,"line":274},[140,759,161],{"emptyLinePlaceholder":160},[140,761,762,765,768],{"class":142,"line":288},[140,763,764],{"class":150},"    return",[140,766,767],{"class":187}," streamText",[140,769,501],{"class":146},[140,771,772,775,778,780,783],{"class":142,"line":298},[140,773,774],{"class":146},"      model: ",[140,776,777],{"class":187},"model",[140,779,713],{"class":146},[140,781,782],{"class":378},"'gpt-5-nano'",[140,784,785],{"class":146},"),\n",[140,787,789,792,795],{"class":142,"line":788},18,[140,790,791],{"class":146},"      system: ",[140,793,794],{"class":378},"`You are a helpful assistant.`",[140,796,519],{"class":146},[140,798,800,803,806],{"class":142,"line":799},19,[140,801,802],{"class":146},"      messages: ",[140,804,805],{"class":187},"convertToModelMessages",[140,807,808],{"class":146},"(messages),\n",[140,810,812,815,818],{"class":142,"line":811},20,[140,813,814],{"class":146},"    }).",[140,816,817],{"class":187},"toUIMessageStreamResponse",[140,819,670],{"class":146},[140,821,823],{"class":142,"line":822},21,[140,824,698],{"class":146},[140,826,828],{"class":142,"line":827},22,[140,829,535],{"class":146},[10,831,832],{},"There are two important sections in this file.",[65,834,835],{},[23,836,837,576],{},[27,838,839],{},"Creating the OpenAI Model",[129,841,843],{"className":482,"code":842,"language":485,"meta":135,"style":135},"const model = createOpenAI({\n  apiKey: runtimeConfig.openAiApiKey,\n})\n",[137,844,845,858,863],{"__ignoreMap":135},[140,846,847,850,852,854,856],{"class":142,"line":143},[140,848,849],{"class":150},"const",[140,851,681],{"class":181},[140,853,664],{"class":150},[140,855,686],{"class":187},[140,857,501],{"class":146},[140,859,860],{"class":142,"line":157},[140,861,862],{"class":146},"  apiKey: runtimeConfig.openAiApiKey,\n",[140,864,865],{"class":142,"line":164},[140,866,535],{"class":146},[10,868,869,870,873],{},"This creates the adapter for the OpenAI model. If you wish to use another provider, change the adapter creation code. This is also where we use the ",[137,871,872],{},"openAiApiKey"," from the runtime config.",[65,875,876],{"start":157},[23,877,878,576],{},[27,879,880],{},"Streaming Text Responses",[129,882,884],{"className":482,"code":883,"language":485,"meta":135,"style":135},"return streamText({\n  model: model('gpt-5-nano'),\n  system: `You are a helpful assistant.`,\n  messages: convertToModelMessages(messages),\n}).toUIMessageStreamResponse()\n",[137,885,886,895,908,917,926],{"__ignoreMap":135},[140,887,888,891,893],{"class":142,"line":143},[140,889,890],{"class":150},"return",[140,892,767],{"class":187},[140,894,501],{"class":146},[140,896,897,900,902,904,906],{"class":142,"line":157},[140,898,899],{"class":146},"  model: ",[140,901,777],{"class":187},[140,903,713],{"class":146},[140,905,782],{"class":378},[140,907,785],{"class":146},[140,909,910,913,915],{"class":142,"line":164},[140,911,912],{"class":146},"  system: ",[140,914,794],{"class":378},[140,916,519],{"class":146},[140,918,919,922,924],{"class":142,"line":173},[140,920,921],{"class":146},"  messages: ",[140,923,805],{"class":187},[140,925,808],{"class":146},[140,927,928,931,933],{"class":142,"line":194},[140,929,930],{"class":146},"}).",[140,932,817],{"class":187},[140,934,670],{"class":146},[10,936,937,938,941,942,948,949,103],{},"The second important section is the streaming of text responses. We use the ",[137,939,940],{},"streamText"," function from the AI SDK to stream the AI-generated responses back to the client. We give it the model, a system prompt, and the user messages. The ",[91,943,946],{"href":944,"rel":945},"https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Freference\u002Fai-sdk-core\u002Fstream-text#to-ui-message-stream-response",[95],[137,947,817],{}," function transforms the response into a format suitable for building the frontend. If you want only the text, you could use ",[91,950,953],{"href":951,"rel":952},"https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Freference\u002Fai-sdk-core\u002Fstream-text#to-text-stream-response",[95],[137,954,955],{},"toTextStreamResponse",[10,957,958],{},"All of these components are wrapped in a lazy event handler to ensure the model is only created once, on the first request. This avoids having each request create a new model instance.",[10,960,961,962,965],{},"You can test your AI Agent endpoint using the following ",[137,963,964],{},"curl"," command:",[129,967,969],{"className":365,"code":968,"filename":367,"language":368,"meta":135,"style":135},"curl -X POST http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"parts\": [\n          {\n            \"type\": \"text\",\n            \"text\": \"Why is the sky blue?\"\n          }\n        ]\n      }\n    ]\n  }'\n",[137,970,971,987,997,1005,1010,1015,1020,1025,1030,1035,1040,1045,1050,1055,1060],{"__ignoreMap":135},[140,972,973,975,978,981,984],{"class":142,"line":143},[140,974,964],{"class":187},[140,976,977],{"class":181}," -X",[140,979,980],{"class":378}," POST",[140,982,983],{"class":378}," http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat",[140,985,986],{"class":181}," \\\n",[140,988,989,992,995],{"class":142,"line":157},[140,990,991],{"class":181},"  -H",[140,993,994],{"class":378}," \"Content-Type: application\u002Fjson\"",[140,996,986],{"class":181},[140,998,999,1002],{"class":142,"line":164},[140,1000,1001],{"class":181},"  -d",[140,1003,1004],{"class":378}," '{\n",[140,1006,1007],{"class":142,"line":173},[140,1008,1009],{"class":378},"    \"messages\": [\n",[140,1011,1012],{"class":142,"line":194},[140,1013,1014],{"class":378},"      {\n",[140,1016,1017],{"class":142,"line":206},[140,1018,1019],{"class":378},"        \"role\": \"user\",\n",[140,1021,1022],{"class":142,"line":211},[140,1023,1024],{"class":378},"        \"parts\": [\n",[140,1026,1027],{"class":142,"line":226},[140,1028,1029],{"class":378},"          {\n",[140,1031,1032],{"class":142,"line":235},[140,1033,1034],{"class":378},"            \"type\": \"text\",\n",[140,1036,1037],{"class":142,"line":241},[140,1038,1039],{"class":378},"            \"text\": \"Why is the sky blue?\"\n",[140,1041,1042],{"class":142,"line":246},[140,1043,1044],{"class":378},"          }\n",[140,1046,1047],{"class":142,"line":258},[140,1048,1049],{"class":378},"        ]\n",[140,1051,1052],{"class":142,"line":264},[140,1053,1054],{"class":378},"      }\n",[140,1056,1057],{"class":142,"line":269},[140,1058,1059],{"class":378},"    ]\n",[140,1061,1062],{"class":142,"line":274},[140,1063,1064],{"class":378},"  }'\n",[10,1066,1067,1068,1071],{},"This command sends a sample user message to your ",[137,1069,1070],{},"\u002Fapi\u002Fchat"," endpoint and streams back the AI-generated response.",[333,1073,1074,1075,1074,1084],{},"\n  ",[1076,1077,1078,1079,1074],"video",{"autoPlay":160,"loop":160,"muted":160,"playsInline":160},"\n    ",[1080,1081],"source",{"src":1082,"type":1083},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fstreaming.mp4","video\u002Fmp4",[341,1085,1086],{},"The AI Agent streaming text responses.",[10,1088,1089],{},"At this stage, the endpoint can stream a text response.",[356,1091,1093],{"id":1092},"calling-a-tool","Calling a tool",[10,1095,1096],{},"Now we can add a tool to our AI Agent. As a reminder, tools are functions that the AI Agent can call to perform specific tasks; the code runs on the server, not in the AI provider.",[10,1098,1099],{},"For this example, we'll add a simple addition tool. Before going further, install Zod to create schemas:",[129,1101,1103],{"className":365,"code":1102,"filename":367,"language":368,"meta":135,"style":135},"pnpm add zod\n",[137,1104,1105],{"__ignoreMap":135},[140,1106,1107,1109,1111],{"class":142,"line":143},[140,1108,375],{"class":187},[140,1110,433],{"class":378},[140,1112,1113],{"class":378}," zod\n",[10,1115,1116,1117,1120],{},"Now add the ",[137,1118,1119],{},"addition"," tool to our AI Agent:",[129,1122,1125],{"className":482,"code":1123,"filename":133,"highlights":1124,"language":485,"meta":135,"style":135},"return streamText({\n  model: model('gpt-5-nano'),\n  system: `You are a helpful assistant.`,\n  tools: {\n    addition: tool({\n      description: 'Adds two numbers',\n      inputSchema: z.object({\n        a: z.number().describe('The first number'),\n        b: z.number().describe('The second number'),\n      }),\n      execute: ({ a, b }) => ({\n        a,\n        b,\n        result: a + b\n      }),\n    }),\n  },\n  messages: convertToModelMessages(messages),\n}).toUIMessageStreamResponse()\n",[173,194,206,211,226,235,241,246,258,264,269,274,288,298],[137,1126,1127,1135,1147,1155,1161,1171,1182,1193,1215,1234,1240,1265,1271,1277,1289,1294,1300,1305,1313],{"__ignoreMap":135},[140,1128,1129,1131,1133],{"class":142,"line":143},[140,1130,890],{"class":150},[140,1132,767],{"class":187},[140,1134,501],{"class":146},[140,1136,1137,1139,1141,1143,1145],{"class":142,"line":157},[140,1138,899],{"class":146},[140,1140,777],{"class":187},[140,1142,713],{"class":146},[140,1144,782],{"class":378},[140,1146,785],{"class":146},[140,1148,1149,1151,1153],{"class":142,"line":164},[140,1150,912],{"class":146},[140,1152,794],{"class":378},[140,1154,519],{"class":146},[140,1156,1158],{"class":1157,"line":173},[142,510],[140,1159,1160],{"class":146},"  tools: {\n",[140,1162,1164,1167,1169],{"class":1163,"line":194},[142,510],[140,1165,1166],{"class":146},"    addition: ",[140,1168,42],{"class":187},[140,1170,501],{"class":146},[140,1172,1174,1177,1180],{"class":1173,"line":206},[142,510],[140,1175,1176],{"class":146},"      description: ",[140,1178,1179],{"class":378},"'Adds two numbers'",[140,1181,519],{"class":146},[140,1183,1185,1188,1191],{"class":1184,"line":211},[142,510],[140,1186,1187],{"class":146},"      inputSchema: z.",[140,1189,1190],{"class":187},"object",[140,1192,501],{"class":146},[140,1194,1196,1199,1202,1205,1208,1210,1213],{"class":1195,"line":226},[142,510],[140,1197,1198],{"class":146},"        a: z.",[140,1200,1201],{"class":187},"number",[140,1203,1204],{"class":146},"().",[140,1206,1207],{"class":187},"describe",[140,1209,713],{"class":146},[140,1211,1212],{"class":378},"'The first number'",[140,1214,785],{"class":146},[140,1216,1218,1221,1223,1225,1227,1229,1232],{"class":1217,"line":235},[142,510],[140,1219,1220],{"class":146},"        b: z.",[140,1222,1201],{"class":187},[140,1224,1204],{"class":146},[140,1226,1207],{"class":187},[140,1228,713],{"class":146},[140,1230,1231],{"class":378},"'The second number'",[140,1233,785],{"class":146},[140,1235,1237],{"class":1236,"line":241},[142,510],[140,1238,1239],{"class":146},"      }),\n",[140,1241,1243,1246,1249,1251,1254,1257,1260,1262],{"class":1242,"line":246},[142,510],[140,1244,1245],{"class":187},"      execute",[140,1247,1248],{"class":146},": ({ ",[140,1250,91],{"class":722},[140,1252,1253],{"class":146},", ",[140,1255,1256],{"class":722},"b",[140,1258,1259],{"class":146}," }) ",[140,1261,650],{"class":150},[140,1263,1264],{"class":146}," ({\n",[140,1266,1268],{"class":1267,"line":258},[142,510],[140,1269,1270],{"class":146},"        a,\n",[140,1272,1274],{"class":1273,"line":264},[142,510],[140,1275,1276],{"class":146},"        b,\n",[140,1278,1280,1283,1286],{"class":1279,"line":269},[142,510],[140,1281,1282],{"class":146},"        result: a ",[140,1284,1285],{"class":150},"+",[140,1287,1288],{"class":146}," b\n",[140,1290,1292],{"class":1291,"line":274},[142,510],[140,1293,1239],{"class":146},[140,1295,1297],{"class":1296,"line":288},[142,510],[140,1298,1299],{"class":146},"    }),\n",[140,1301,1303],{"class":1302,"line":298},[142,510],[140,1304,524],{"class":146},[140,1306,1307,1309,1311],{"class":142,"line":788},[140,1308,921],{"class":146},[140,1310,805],{"class":187},[140,1312,808],{"class":146},[140,1314,1315,1317,1319],{"class":142,"line":799},[140,1316,930],{"class":146},[140,1318,817],{"class":187},[140,1320,670],{"class":146},[10,1322,1323],{},"Finally, update our prompt to ensure the AI will use the new tool:",[129,1325,1328],{"className":482,"code":1326,"filename":133,"highlights":1327,"language":485,"meta":135,"style":135},"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  \u002F\u002F ...\n}).toUIMessageStreamResponse()\n",[164],[137,1329,1330,1338,1350,1360,1364],{"__ignoreMap":135},[140,1331,1332,1334,1336],{"class":142,"line":143},[140,1333,890],{"class":150},[140,1335,767],{"class":187},[140,1337,501],{"class":146},[140,1339,1340,1342,1344,1346,1348],{"class":142,"line":157},[140,1341,899],{"class":146},[140,1343,777],{"class":187},[140,1345,713],{"class":146},[140,1347,782],{"class":378},[140,1349,785],{"class":146},[140,1351,1353,1355,1358],{"class":1352,"line":164},[142,510],[140,1354,912],{"class":146},[140,1356,1357],{"class":378},"`You are a helpful assistant. You can use the tool to add two numbers together.`",[140,1359,519],{"class":146},[140,1361,1362],{"class":142,"line":173},[140,1363,530],{"class":529},[140,1365,1366,1368,1370],{"class":142,"line":194},[140,1367,930],{"class":146},[140,1369,817],{"class":187},[140,1371,670],{"class":146},[10,1373,1374],{},"And let's give it a try:",[129,1376,1378],{"className":365,"code":1377,"filename":367,"language":368,"meta":135,"style":135},"curl -X POST http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"parts\": [\n          {\n            \"type\": \"text\",\n            \"text\": \"What is 2 + 2?\"\n          }\n        ]\n      }\n    ]\n  }'\n",[137,1379,1380,1392,1400,1406,1410,1414,1418,1422,1426,1430,1435,1439,1443,1447,1451],{"__ignoreMap":135},[140,1381,1382,1384,1386,1388,1390],{"class":142,"line":143},[140,1383,964],{"class":187},[140,1385,977],{"class":181},[140,1387,980],{"class":378},[140,1389,983],{"class":378},[140,1391,986],{"class":181},[140,1393,1394,1396,1398],{"class":142,"line":157},[140,1395,991],{"class":181},[140,1397,994],{"class":378},[140,1399,986],{"class":181},[140,1401,1402,1404],{"class":142,"line":164},[140,1403,1001],{"class":181},[140,1405,1004],{"class":378},[140,1407,1408],{"class":142,"line":173},[140,1409,1009],{"class":378},[140,1411,1412],{"class":142,"line":194},[140,1413,1014],{"class":378},[140,1415,1416],{"class":142,"line":206},[140,1417,1019],{"class":378},[140,1419,1420],{"class":142,"line":211},[140,1421,1024],{"class":378},[140,1423,1424],{"class":142,"line":226},[140,1425,1029],{"class":378},[140,1427,1428],{"class":142,"line":235},[140,1429,1034],{"class":378},[140,1431,1432],{"class":142,"line":241},[140,1433,1434],{"class":378},"            \"text\": \"What is 2 + 2?\"\n",[140,1436,1437],{"class":142,"line":246},[140,1438,1044],{"class":378},[140,1440,1441],{"class":142,"line":258},[140,1442,1049],{"class":378},[140,1444,1445],{"class":142,"line":264},[140,1446,1054],{"class":378},[140,1448,1449],{"class":142,"line":269},[140,1450,1059],{"class":378},[140,1452,1453],{"class":142,"line":274},[140,1454,1064],{"class":378},[333,1456,1074,1457,1074,1462],{},[1076,1458,1078,1459,1074],{"autoPlay":160,"loop":160,"muted":160,"playsInline":160},[1080,1460],{"src":1461,"type":1083},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fusing-tools.mp4",[341,1463,1464],{},"The AI Agent using a tool to perform a calculation.",[10,1466,1467],{},"Notice what is missing from the response.",[10,1469,1470],{},"The AI performs the calculation using the addition tool:",[129,1472,1476],{"className":1473,"code":1474,"filename":133,"language":1475,"meta":135,"style":135},"language-txt shiki shiki-themes github-light github-light github-dark","data: {\"type\":\"tool-output-available\",\"toolCallId\":\"call_Zmi5NtcVDRFZsZHcsULlutnG\",\"output\":{\"a\":12,\"b\":24,\"result\":36}}\n","txt",[137,1477,1478],{"__ignoreMap":135},[140,1479,1480],{"class":142,"line":143},[140,1481,1474],{},[10,1483,1484],{},"The tool executed successfully, but this run stops after the tool result. The model has not yet received that result in a new step, so it has not generated a final answer such as \"The answer is 36.\" We need to let it continue.",[356,1486,1488],{"id":1487},"making-it-an-agent","Making it an agent",[10,1490,1491],{},"The AI SDK handles the loop for us. We only need to set a maximum number of steps.",[129,1493,1495],{"className":482,"code":1494,"filename":133,"language":485,"meta":135,"style":135},"import { stepCountIs, streamText } from 'ai'\n\nreturn 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  stopWhen: stepCountIs(2),\n  \u002F\u002F ...\n}).toUIMessageStreamResponse()\n",[137,1496,1497,1508,1512,1520,1532,1540,1555,1559],{"__ignoreMap":135},[140,1498,1499,1501,1504,1506],{"class":142,"line":143},[140,1500,586],{"class":150},[140,1502,1503],{"class":146}," { stepCountIs, streamText } ",[140,1505,592],{"class":150},[140,1507,607],{"class":378},[140,1509,1510],{"class":142,"line":157},[140,1511,161],{"emptyLinePlaceholder":160},[140,1513,1514,1516,1518],{"class":142,"line":164},[140,1515,890],{"class":150},[140,1517,767],{"class":187},[140,1519,501],{"class":146},[140,1521,1522,1524,1526,1528,1530],{"class":142,"line":173},[140,1523,899],{"class":146},[140,1525,777],{"class":187},[140,1527,713],{"class":146},[140,1529,782],{"class":378},[140,1531,785],{"class":146},[140,1533,1534,1536,1538],{"class":142,"line":194},[140,1535,912],{"class":146},[140,1537,1357],{"class":378},[140,1539,519],{"class":146},[140,1541,1542,1545,1548,1550,1553],{"class":142,"line":206},[140,1543,1544],{"class":146},"  stopWhen: ",[140,1546,1547],{"class":187},"stepCountIs",[140,1549,713],{"class":146},[140,1551,1552],{"class":181},"2",[140,1554,785],{"class":146},[140,1556,1557],{"class":142,"line":211},[140,1558,530],{"class":529},[140,1560,1561,1563,1565],{"class":142,"line":226},[140,1562,930],{"class":146},[140,1564,817],{"class":187},[140,1566,670],{"class":146},[10,1568,1569,1570,1573],{},"The ",[137,1571,1572],{},"stopWhen: stepCountIs(2)"," option allows up to two steps: one for the tool call and one for the answer based on its result. The SDK also stops when the latest step produces a final text response. Real agents may need a higher, carefully bounded limit when a task requires several tools.",[77,1575,1576],{"color":79,"icon":80},[10,1577,1578,1579,1584],{},"I recommend reading the ",[91,1580,1583],{"href":1581,"rel":1582},"https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Fagents\u002Floop-control",[95],"Loop Control page"," in the documentation to understand what happens under the hood.",[10,1586,1587],{},"Let's give it a try:",[129,1589,1590],{"className":365,"code":1377,"filename":367,"language":368,"meta":135,"style":135},[137,1591,1592,1604,1612,1618,1622,1626,1630,1634,1638,1642,1646,1650,1654,1658,1662],{"__ignoreMap":135},[140,1593,1594,1596,1598,1600,1602],{"class":142,"line":143},[140,1595,964],{"class":187},[140,1597,977],{"class":181},[140,1599,980],{"class":378},[140,1601,983],{"class":378},[140,1603,986],{"class":181},[140,1605,1606,1608,1610],{"class":142,"line":157},[140,1607,991],{"class":181},[140,1609,994],{"class":378},[140,1611,986],{"class":181},[140,1613,1614,1616],{"class":142,"line":164},[140,1615,1001],{"class":181},[140,1617,1004],{"class":378},[140,1619,1620],{"class":142,"line":173},[140,1621,1009],{"class":378},[140,1623,1624],{"class":142,"line":194},[140,1625,1014],{"class":378},[140,1627,1628],{"class":142,"line":206},[140,1629,1019],{"class":378},[140,1631,1632],{"class":142,"line":211},[140,1633,1024],{"class":378},[140,1635,1636],{"class":142,"line":226},[140,1637,1029],{"class":378},[140,1639,1640],{"class":142,"line":235},[140,1641,1034],{"class":378},[140,1643,1644],{"class":142,"line":241},[140,1645,1434],{"class":378},[140,1647,1648],{"class":142,"line":246},[140,1649,1044],{"class":378},[140,1651,1652],{"class":142,"line":258},[140,1653,1049],{"class":378},[140,1655,1656],{"class":142,"line":264},[140,1657,1054],{"class":378},[140,1659,1660],{"class":142,"line":269},[140,1661,1059],{"class":378},[140,1663,1664],{"class":142,"line":274},[140,1665,1064],{"class":378},[333,1667,1074,1668,1074,1673],{},[1076,1669,1078,1670,1074],{"autoPlay":160,"loop":160,"muted":160,"playsInline":160},[1080,1671],{"src":1672,"type":1083},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fai-agent.mp4",[341,1674,1675],{},"The AI Agent using a tool and generating a response.",[10,1677,1678],{},"Our agent can now use a tool and generate an answer from its output. In the next article, we will move that tool into an MCP server so it can be reused beyond this single application.",[1680,1681,1682],"style",{},"html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}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 .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":135,"searchDepth":157,"depth":157,"links":1684},[1685,1686,1687],{"id":59,"depth":157,"text":60},{"id":120,"depth":157,"text":121},{"id":315,"depth":157,"text":316,"children":1688},[1689,1690,1691,1692,1693],{"id":358,"depth":164,"text":359},{"id":414,"depth":164,"text":415},{"id":541,"depth":164,"text":542},{"id":1092,"depth":164,"text":1093},{"id":1487,"depth":164,"text":1488},"9ffbf543-f6d5-45d3-ae35-eb1bfb26843e","2025-10-07","AI agents can be mysterious, but they are not as complicated as they seem. Let's prove it with in-depth explanations and examples.","md",{"branch":1699},"01.building-an-ai-agent-made-easy-thanks-to-the-ai-sdk",null,{},"\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk","---\ncontentId: 9ffbf543-f6d5-45d3-ae35-eb1bfb26843e\npart: 1\ntitle: Building an AI Agent Made Easy Thanks to the AI SDK\ndescription: AI agents can be mysterious, but they are not as complicated as they seem. Let's prove it with in-depth explanations and examples.\ngithub:\n  branch: 01.building-an-ai-agent-made-easy-thanks-to-the-ai-sdk\ndate: 2025-10-07\nseriesSlug: ai-agents-and-mcp-server-teaming-up-for-the-agentic-web\n---\n\nBefore going any further, what's an AI Agent? Clarifying that concept will make the rest of the series easier to follow.\n\nAn AI Agent is software that uses a model to work toward a user's goal. It can interpret a natural-language request, decide whether it needs an external capability, use that capability, and continue until it can provide a useful result. This makes interactions with software more natural: the user describes the outcome they want instead of manually coordinating every step.\n\nThroughout this series, we will use five terms consistently:\n\n- An **AI application** is the chat product a person uses.\n- An **AI agent** is the server-side orchestration that gives the model access to tools and lets it continue after using them.\n- A **tool** is a function the agent can ask its host application to run.\n- An **MCP server** exposes tools through the Model Context Protocol.\n- An **MCP client** connects the agent to an MCP server.\n\n## What the Model Can Do\n\nTo keep the series focused, we'll work with text-based LLMs. In this example, the model can:\n\n1. Generate text from the messages it receives.\n2. Use the available context to decide what to say or do next.\n3. Request a tool call so the host application can perform an action outside the model.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nDepending on the provider, there may be additional functionalities available, like built-in tools or MCP tools. Ultimately, everything is considered a tool, whether it's a built-in function, an external API via MCP, or a custom tool.\n::\n\nWhen you interact with an AI, the model may use one or more of these capabilities. Its internal reasoning is model- and provider-specific, and it may not be exposed to your application. A model can also produce text before, between, or after tool calls.\n\nThe important part for us is this: after a tool call completes, the result must be given back to the model so it can decide what to do next. The latest models can [call multiple tools](https:\u002F\u002Fopenai.com\u002Findex\u002Fintroducing-gpt-5-for-developers\u002F#:~:text=making%20many%20tool%20calls%20in%20sequence%20or%20in%20parallel), including in sequence or in parallel, and can [generate progress updates around tool calls](https:\u002F\u002Fopenai.com\u002Findex\u002Fintroducing-gpt-5-for-developers\u002F#:~:text=GPT%E2%80%915%20can%20also%20output%20preamble%20messages%20before%20and%20between%20tool%20calls%20to%20update%20users%20on%20progress%20during%20longer%20agentic%20tasks.).\n\nWithout orchestration, a tool call may be the last event your application handles. The user would see that the calculation happened but would not receive the model's final answer. Our agent will handle that follow-up automatically.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nIt's important to note that the AI does not run custom tools directly. It asks the client, via a dedicated response, to call the tool on its behalf. That's why defining tools is often just defining a JSON schema. I recommend reading the [tool calling flow](https:\u002F\u002Fplatform.openai.com\u002Fdocs\u002Fguides\u002Ffunction-calling#the-tool-calling-flow) in the OpenAI documentation.\n::\n\n## Continuing after a tool call\n\nTo solve this problem, the application needs a bounded loop. When the model asks for a tool, the application runs it, adds the result to the conversation, and lets the model continue.\n\nIn simplified pseudo-code, that looks like this:\n\n```js [Example]\nmessages = [userInput]\n\nwhile (hasStepsRemaining) {\n  response = AI.ask(messages)\n  messages.push(response)\n\n  if (response.hasReasoning()) {\n    showProgress(response.reasoning)\n  }\n\n  if (response.isText()) {\n    break\n  }\n\n  toolResult = runTool(response.toolCall)\n  messages.push(toolResult)\n}\n```\n\n`response.hasReasoning()` is optional: whether an application receives reasoning depends on the model and provider. When it is available, it can be shown as progress, but the full response must still be added to the conversation so the next step has the tool call and any associated model context. This loop is not the definition of an AI Agent. It is the mechanism that lets an agent work through a task across multiple model and tool steps.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nTo avoid an infinite loop, define a maximum number of iterations.\n::\n\n## Our agent\n\nI think we're ready to start building our AI Agent.\n\nFor this series, we will use the [AI SDK](https:\u002F\u002Fai-sdk.dev). We could have used a provider SDK such as OpenAI's or Anthropic's, but the AI SDK gives us a higher-level interface while keeping the provider interchangeable.\n\nTo make sure we're all on the same page, here's a quick overview of the infrastructure we're building.\n\n![AI Agent Infrastructure.](\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fai-agent-infrastructure.webp)\n\nFor this part, we'll focus on the server-side implementation and the communication with the provider.\n\nTo do so, we'll use [Nitro](https:\u002F\u002Fnitro.build\u002F), but you can use any JS backend framework of your choice.\n\n### Installation\n\nFirst, create a new Nitro project:\n\n```bash [terminal]\npnpm dlx giget@latest nitro ai-agent --install\n```\n\nThen remove the `server\u002Froutes\u002Findex.ts` file, which we won't need:\n\n```bash [server\u002Froutes\u002Findex.ts]\nrm server\u002Froutes\u002Findex.ts\n```\n\n### Starting with the AI SDK\n\nNow that our backend is set up, we can start working with the AI SDK.\n\nInstall the SDK:\n\n```bash [terminal]\npnpm add ai @ai-sdk\u002Fopenai\n```\n\nWe also install the OpenAI adapter to communicate with the OpenAI API, but you can use [any other adapter](https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Ffoundations\u002Fproviders-and-models#providers-and-models) you prefer.\n\nTo communicate with OpenAI, set up an API key. You can obtain one by creating an account on the [OpenAI website](https:\u002F\u002Fplatform.openai.com\u002Fsignup). Then set the `OPENAI_API_KEY` environment variable in your `.env` file:\n\n```ini [Example]\nNITRO_OPEN_AI_API_KEY=\n```\n\nFinally, create a runtime variable within the Nitro configuration:\n\n```ts [Example] {3}\nexport default defineNitroConfig({\n  runtimeConfig: {\n    openAiApiKey: '',\n  },\n  \u002F\u002F ...\n})\n```\n\nNow we're ready to start building our AI Agent.\n\n### Streaming some text\n\nThe first step is to make sure our AI Agent can generate text based on user input. This may be more challenging than it seems, but the AI SDK provides a simple way to achieve it.\n\nCreate a new endpoint in the Nitro server that will receive the user query and return the AI-generated response:\n\n```bash [terminal]\nmkdir server\u002Fapi\ntouch server\u002Fapi\u002Fchat.ts\n```\n\nThen create the endpoint in `server\u002Fapi\u002Fchat.ts`:\n\n```ts [server\u002Fapi\u002Fchat.ts]\nimport { createOpenAI } from '@ai-sdk\u002Fopenai'\nimport { convertToModelMessages, streamText } from 'ai'\nimport { defineEventHandler, defineLazyEventHandler, readBody } from 'h3'\nimport { useRuntimeConfig } from 'nitropack\u002Fruntime'\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.`,\n      messages: convertToModelMessages(messages),\n    }).toUIMessageStreamResponse()\n  })\n})\n```\n\nThere are two important sections in this file.\n\n1. **Creating the OpenAI Model**:\n\n  ```ts\n  const model = createOpenAI({\n    apiKey: runtimeConfig.openAiApiKey,\n  })\n  ```\n\n  This creates the adapter for the OpenAI model. If you wish to use another provider, change the adapter creation code. This is also where we use the `openAiApiKey` from the runtime config.\n\n2. **Streaming Text Responses**:\n\n  ```ts\n  return streamText({\n    model: model('gpt-5-nano'),\n    system: `You are a helpful assistant.`,\n    messages: convertToModelMessages(messages),\n  }).toUIMessageStreamResponse()\n  ```\n\n  The second important section is the streaming of text responses. We use the `streamText` function from the AI SDK to stream the AI-generated responses back to the client. We give it the model, a system prompt, and the user messages. The [`toUIMessageStreamResponse`](https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Freference\u002Fai-sdk-core\u002Fstream-text#to-ui-message-stream-response) function transforms the response into a format suitable for building the frontend. If you want only the text, you could use [`toTextStreamResponse`](https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Freference\u002Fai-sdk-core\u002Fstream-text#to-text-stream-response).\n\nAll of these components are wrapped in a lazy event handler to ensure the model is only created once, on the first request. This avoids having each request create a new model instance.\n\nYou can test your AI Agent endpoint using the following `curl` command:\n\n```bash [terminal]\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"parts\": [\n          {\n            \"type\": \"text\",\n            \"text\": \"Why is the sky blue?\"\n          }\n        ]\n      }\n    ]\n  }'\n```\n\nThis command sends a sample user message to your `\u002Fapi\u002Fchat` endpoint and streams back the AI-generated response.\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\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fstreaming.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>The AI Agent streaming text responses.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\nAt this stage, the endpoint can stream a text response.\n\n### Calling a tool\n\nNow we can add a tool to our AI Agent. As a reminder, tools are functions that the AI Agent can call to perform specific tasks; the code runs on the server, not in the AI provider.\n\nFor this example, we'll add a simple addition tool. Before going further, install Zod to create schemas:\n\n```bash [terminal]\npnpm add zod\n```\n\nNow add the `addition` tool to our AI Agent:\n\n```ts [Example] {4-17}\nreturn streamText({\n  model: model('gpt-5-nano'),\n  system: `You are a helpful assistant.`,\n  tools: {\n    addition: tool({\n      description: 'Adds two numbers',\n      inputSchema: z.object({\n        a: z.number().describe('The first number'),\n        b: z.number().describe('The second number'),\n      }),\n      execute: ({ a, b }) => ({\n        a,\n        b,\n        result: a + b\n      }),\n    }),\n  },\n  messages: convertToModelMessages(messages),\n}).toUIMessageStreamResponse()\n```\n\nFinally, update our prompt to ensure the AI will use the new tool:\n\n```ts [Example] {3}\nreturn 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  \u002F\u002F ...\n}).toUIMessageStreamResponse()\n```\n\nAnd let's give it a try:\n\n```bash [terminal]\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"parts\": [\n          {\n            \"type\": \"text\",\n            \"text\": \"What is 2 + 2?\"\n          }\n        ]\n      }\n    ]\n  }'\n```\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\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fusing-tools.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>The AI Agent using a tool to perform a calculation.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\nNotice what is missing from the response.\n\nThe AI performs the calculation using the addition tool:\n\n```txt [Example]\ndata: {\"type\":\"tool-output-available\",\"toolCallId\":\"call_Zmi5NtcVDRFZsZHcsULlutnG\",\"output\":{\"a\":12,\"b\":24,\"result\":36}}\n```\n\nThe tool executed successfully, but this run stops after the tool result. The model has not yet received that result in a new step, so it has not generated a final answer such as \"The answer is 36.\" We need to let it continue.\n\n### Making it an agent\n\nThe AI SDK handles the loop for us. We only need to set a maximum number of steps.\n\n```ts [Example]\nimport { stepCountIs, streamText } from 'ai'\n\nreturn 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  stopWhen: stepCountIs(2),\n  \u002F\u002F ...\n}).toUIMessageStreamResponse()\n```\n\nThe `stopWhen: stepCountIs(2)` option allows up to two steps: one for the tool call and one for the answer based on its result. The SDK also stops when the latest step produces a final text response. Real agents may need a higher, carefully bounded limit when a task requires several tools.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nI recommend reading the [Loop Control page](https:\u002F\u002Fai-sdk.dev\u002Fdocs\u002Fagents\u002Floop-control) in the documentation to understand what happens under the hood.\n::\n\nLet's give it a try:\n\n```bash [terminal]\ncurl -X POST http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fchat \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"parts\": [\n          {\n            \"type\": \"text\",\n            \"text\": \"What is 2 + 2?\"\n          }\n        ]\n      }\n    ]\n  }'\n```\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\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk\u002Fai-agent.mp4\" type=\"video\u002Fmp4\">\n  \u003C\u002Fvideo>\n  \u003Cfigcaption>The AI Agent using a tool and generating a response.\u003C\u002Ffigcaption>\n\u003C\u002Ffigure>\n\nOur agent can now use a tool and generate an answer from its output. In the next article, we will move that tool into an MCP server so it can be reused beyond this single application.\n",{"title":5,"description":1696},"ai-agents-and-mcp-server-teaming-up-for-the-agentic-web",{"loc":1702,"images":1707},[1708],{"loc":339},"series\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fbuilding-an-ai-agent-made-easy-thanks-to-the-ai-sdk","1tZcgvcMD4Ljs0Ka2COuu73-XX56lV7UIpnTvTzEoyo",{"overview":1712,"chapters":1818},{"id":1713,"title":1714,"body":1715,"contentId":1797,"date":1695,"description":1798,"extension":1697,"github":1799,"meetTheInstructor":1802,"meta":1803,"navigation":160,"part":1700,"path":1804,"rawbody":1805,"robots":1700,"schemaOrg":1700,"seo":1806,"seriesSlug":1705,"sitemap":1807,"stem":1808,"subtitle":1809,"topics":1810,"__hash__":1817},"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":1716,"toc":1794},[1717,1720,1723,1731,1734,1737,1740,1771,1774,1784,1788],[10,1718,1719],{},"Hey 👋,",[10,1721,1722],{},"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,1724,1725,1726,1730],{},"This series is not about the exact implementation details of my AI Agent. I have already written two articles about that. The first covers ",[91,1727,1729],{"href":1728},"\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,1732,1733],{},"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,1735,1736],{},"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,1738,1739],{},"Throughout this series, we will:",[65,1741,1742,1747,1753,1759,1765],{},[23,1743,1744,1746],{},[27,1745,5],{},": Using the AI SDK, we'll build our first AI Agent and understand what makes it different from a traditional AI.",[23,1748,1749,1752],{},[27,1750,1751],{},"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.",[23,1754,1755,1758],{},[27,1756,1757],{},"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.",[23,1760,1761,1764],{},[27,1762,1763],{},"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.",[23,1766,1767,1770],{},[27,1768,1769],{},"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,1772,1773],{},"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.",[333,1775,1074,1776,1074,1781],{},[1076,1777,1078,1778,1074],{"autoPlay":160,"loop":160,"muted":160,"playsInline":160},[1080,1779],{"src":1780,"type":1083},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fai-application.mp4",[341,1782,1783],{},"Our final AI application.",[57,1785,1787],{"id":1786},"chapters","Chapters",[1789,1790],"series-chapters-list",{"className":1791},[1792,1793],"mx-auto","max-w-5xl",{"title":135,"searchDepth":157,"depth":157,"links":1795},[1796],{"id":1786,"depth":157,"text":1787},"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":1800,"repository":1801},"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":1714,"description":1798},{"loc":1804},"series\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web","Explore the future of the web by building an AI application",[1811,1812,1813,1814,1815,1816],"ai-agents","ai","mcp","agentic-web","nuxt","nuxt-ui","3fbdjQUyeN3fzx5NIJ-SVb3udixzleWLpFXsAeV6Tkw",[1819,1821,1827,1834,1840],{"contentId":1694,"title":5,"description":1696,"path":1702,"part":143,"github":1820,"topics":1700},{"branch":1699},{"contentId":1822,"title":1751,"description":1823,"path":1824,"part":157,"github":1825,"topics":1700},"b5dafecc-480c-4954-ac35-836d4e71c7a3","MCP servers are popping up everywhere. Understanding them is key to unlocking the full potential of AI agents.","\u002Fseries\u002Fai-agents-and-mcp-server-teaming-up-for-the-agentic-web\u002Fmcp-to-provide-additional-capabilities-to-the-ai-agent",{"branch":1826},"02.mcp-to-provide-additional-capabilities-to-the-ai-agent",{"contentId":1828,"title":1829,"description":1830,"path":1831,"part":164,"github":1832,"topics":1700},"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":1833},"03.pairing-ai-agents-with-mcp-to-make-outside-world-accessible",{"contentId":1835,"title":1763,"description":1836,"path":1837,"part":173,"github":1838,"topics":1700},"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":1839},"04.a-powerful-ai-application-made-with-nitro-and-nuxt-ui",{"contentId":1841,"title":1769,"description":1842,"path":1843,"part":194,"github":1844,"topics":1700},"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":1845},"05.deploying-our-ai-agent-to-the-world-using-cloudflare",1795016695247]