When would you use MCP instead of defining tools directly in your app?
Advertisement
🧩 Scenario
Concept Walkthrough
Direct tools: a function in your codebase
A direct tool is just a function you define next to your route handler, with a description and a schema. It is like calling a local helper: no extra process, full access to your request context (session, tenant, feature flags), easy to type and test, and one deploy.
This is the right default when:
- Only your app uses the capability.
- The tool needs your app's internals, like the current user's session or a DB transaction.
- Latency matters and you do not want an extra hop.
MCP: a capability that lives outside your app
An MCP server is more like a microservice with a standard contract. Any MCP host (an IDE, a desktop assistant, your chatbot) can discover and use its tools, resources and prompts. Reach for it when:
- Many hosts need the same capability. Your docs search should work in your support bot and in engineers' IDEs. Build it once as a server.
- Someone already built it. A vendor's official MCP server saves you writing and maintaining an API integration.
- Different owners. The platform team owns the server and its permissions; product teams just connect to it.
- Users bring their own tools. If your product lets users plug in their own integrations, MCP gives them a standard way to do it.
What MCP costs you
- An extra process or network hop on every tool call.
- Another thing to deploy, version and monitor.
- A wider security surface: auth between your app and the server, and trust in the server's descriptions and outputs.
- Token cost: every tool you expose adds its definition to the model input. Pulling in every tool from a big server also makes the model's tool choice less reliable.
Applying it to the scenario
The invoices tool should be direct: it is specific to your app and needs the user's session and DB access. The issue tracker should use its MCP server: someone else maintains the integration, and you only connect a client from your route handler and expose the few tools you need.
Key Code Explained (TypeScript)
// app/api/assistant/route.ts (AI SDK with an MCP client)
import { generateText, tool, isStepCount } from 'ai';
import { createMCPClient } from '@ai-sdk/mcp';
import { z } from 'zod';
import { getSession, db } from '@/lib/server'; // your own helpers
export async function POST(req: Request) {
const { question } = await req.json();
const session = await getSession(req);
// Direct tool: needs this request's session and your DB
const getInvoices = tool({
description: 'List the current user\'s recent invoices.',
inputSchema: z.object({ limit: z.number().int().max(20).default(5) }),
execute: async ({ limit }) => db.invoices.recent(session.userId, limit),
});
// MCP client: a capability someone else maintains
const tracker = await createMCPClient({
transport: {
type: 'http',
url: process.env.TRACKER_MCP_URL!,
headers: { Authorization: `Bearer ${process.env.TRACKER_TOKEN}` },
},
});
try {
const allTrackerTools = await tracker.tools();
// Expose only what this feature needs (tool names depend on the server)
const { create_issue } = allTrackerTools;
const result = await generateText({
model: 'anthropic/claude-sonnet-5.5', // example id
tools: { getInvoices, create_issue },
stopWhen: isStepCount(5),
prompt: question,
});
return Response.json({ answer: result.text });
} finally {
// Always release the connection, even on errors
await tracker.close();
}
}
Both kinds of tool end up in the same tools object, so the model cannot tell them apart. The difference is where the code runs and who maintains it. Picking out only create_issue keeps the prompt small and the model's choices focused.
Tradeoffs
| Factor | Direct tools | MCP server |
|---|---|---|
| Reuse across hosts | No, tied to your app | Yes, any MCP host can connect |
| Access to request context | Full, in-process | Only what you pass over the protocol |
| Latency | Function call | Extra process or network hop |
| Ownership | Your team, your deploy | Can be another team or a vendor |
| Security surface | Your existing app | Server auth, trust in descriptions and outputs |
| Setup effort | Lowest | Server, transport and client wiring |
What Interviewers Actually Check
- Whether you default to the simple option and justify MCP with a real reason
- Whether you mention reuse across hosts and existing servers as the main drivers
- Whether you know MCP does not reduce latency or token cost
- Whether you limit which MCP tools you expose to the model
- Whether you manage the client lifecycle and think about trust in third-party servers
Follow-Up Questions
- Your direct tool is now needed in the team's IDE assistant. How would you migrate it to an MCP server?
- How would you authenticate your Next.js app to an internal MCP server?
- What happens to tool choice quality when you expose 50 tools at once?
- Would you open a new MCP client per request or reuse one? What are the trade-offs?
- How would you review a third-party MCP server before connecting it to production?
Common Candidate Mistakes
- Saying "MCP is the modern way, so always use it". It is a tool for reuse and separation, not a default.
- Ignoring that every exposed tool definition costs input tokens on every request.
- Not closing the client and leaking connections in a serverless route.
- Forgetting that MCP tool outputs are untrusted text going back into the model.
- Moving a tool to MCP and losing access to the user context it needed.
Interview Readiness Checklist
Before you leave this question, make sure you can answer:
- Can you name two good reasons to use MCP and two good reasons not to?
- Can you explain where the code runs in each approach?
- Can you combine MCP tools with direct tools in the AI SDK?
- Can you explain why exposing fewer tools helps?
- Can you describe the security work an MCP server adds?
Summary
Direct tools are functions inside your app: simplest, fastest and with full access to the request context, so they are the right default for features only your app uses. MCP makes sense when a capability should be reused across several AI hosts, when a vendor or another team already maintains a server, or when you want the tool to be owned and deployed separately. MCP does not make calls faster or cheaper. It adds a hop, a deployment and a trust boundary. In the AI SDK you can mix both by spreading an MCP client's tools next to your own, exposing only the tools the feature needs, and closing the client when the request ends.
Does MCP make tool calling faster or cheaper?
No. The model still sees tool definitions as input tokens and still produces tool calls. MCP adds a network or process hop between your app and the tool code. Its benefit is reuse and separation, not speed.
Can I mix MCP tools and direct tools in one request?
Yes. In the AI SDK, tools from an MCP client are a normal tools object, so you can spread them together with your own tool() definitions and pass both to generateText or streamText.
If I add a public MCP server, do I need to worry about its tool descriptions?
Yes. Descriptions go straight into the model context, they cost tokens, and a malicious or careless server can use them to steer the model. Only connect servers you trust, and limit which tools you expose.
Advertisement
Stay Updated
Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.
Advertisement