17. Advanced Patterns: MCP, Agents SDKs, and Frameworks
Compare direct APIs with SDKs, understand MCP-style integrations, and use frameworks without surrendering control.
Direct API, SDK, and Framework Trade-offs
Direct provider APIs offer control and make request semantics visible, but require more orchestration code. An SDK or AI application framework can simplify streaming, schema outputs, tool calls, provider switching, and UI integration. Framework abstractions may evolve quickly and may not expose every provider capability immediately.
Choose based on required capabilities, team familiarity, debuggability, lock-in tolerance, and maintenance. Keep business logic and tool policy in your own modules so changing a framework does not require rewriting domain rules. Pin versions, read migration notes, and test upgrades against evaluations.
Product / domain logic
-> application AI interface
-> provider adapter or framework
-> provider API
-> model- Use the simplest abstraction that meets requirements.
- Keep policy and business rules in application code.
- Pin versions and test upgrades with regression evaluations.
What is a good reason to place business logic outside a framework-specific AI chain?
Model Context Protocol (MCP) Concepts
MCP is a protocol pattern for connecting AI applications to external tools and resources through a standardized interface. A host application may connect to servers that expose tools, resources, or prompts. Standardization can simplify integration, but it does not automatically make a server trustworthy or secure.
Treat each MCP server as a dependency with its own permissions, credentials, network access, and data exposure. Review tools before enabling them, scope credentials, require approval for sensitive operations, and validate results. Distinguish protocol interoperability from authorization: the host still decides which user can invoke which tool.
AI host
-> selects an approved MCP server
-> discovers available tools/resources
-> applies user and tool policy
-> invokes a scoped tool
-> validates result
-> returns relevant data to model- MCP standardizes integration patterns.
- Treat servers as external dependencies.
- Apply least privilege and audit sensitive tool use.
Does using a standardized tool protocol automatically make every tool safe?
Agent Frameworks and Orchestration Libraries
Frameworks can provide tool schemas, agent loops, state, streaming, retrieval adapters, tracing, and human approval patterns. Examples include provider-specific agent SDKs and cross-provider libraries. Their APIs and supported features change quickly, so choose versions intentionally and read official docs for current patterns.
Do not adopt a framework just because a demo is short. Verify how it handles tool authorization, retries, cancellation, persistence, streaming, tracing, and data retention. Understand the underlying loop well enough to debug it, and keep a small direct-API prototype as a baseline when abstraction overhead becomes hard to diagnose.
Compare:
- Provider support and feature parity
- Streaming and structured output
- Tool validation and approvals
- Durable state and retries
- Tracing, evaluations, and debugging
- Runtime compatibility and maintenance- Learn the underlying model/tool loop.
- Verify framework behavior for failures and side effects.
- Keep your domain policy independent of framework internals.
What should be checked before adopting an agent framework for production?