Arrange Act Assert

Jag Reehal's thoughts on things, mostly product development

From Static to Stateful: Revolutionising AI Communication with the MCP Protocol

10 Mar 2025

MCP standardises how AI applications communicate with external systems using JSON‑RPC 2.0 over stateful, bidirectional connections. Unlike standard JSON‑RPC, which treats every request independently, MCP augments the protocol by embedding session tokens and context IDs into each message.

This enhancement provides state, enabling advanced, multi‑step interactions and dynamic module loading at runtime. Such a stateful design is essential for modern, agile AI systems.

Imagine an AI‑powered payments system that dynamically integrates a new fraud detection module during operation. MCP allows the system to load this module on the fly without a full redeployment, provided the server supports dynamic module loading.

In this post, we’ll explore the MCP protocol, its core components, and how it compares to traditional REST and GraphQL APIs.

Core Components

Advantages:

Disadvantages:

MCP Core ComponentsStatefulBidirectionalCommunicationClient(Requests &Callbacks)Protocol Layer(JSON-RPC 2.0+)Server(Tools & Resources)SessionTokensContextIDs

Technical Deep Dive

State Management

MCP’s implementation of statefulness builds on the foundation of JSON‑RPC. While standard JSON‑RPC treats each request as stateless, MCP embeds unique session tokens and context IDs into every message. This approach allows the server to:

State Management Interaction Diagram

[Context Invalid]alt[Context Valid]1234567Initiate Connection (JSON‑RPC Request)Respond with Session Token & Context IDRequest with Session Token & Context IDResponse with Updated ContextFollow-up Request (with updated context)Final Result (context-aware)Error: Invalid ContextSession InitializationStateful InteractionClientServerClientServer

Security

MCP’s security is built on a layered approach, incorporating additional steps to safeguard dynamic interactions and state management.

Security Layers Diagram

Embedded SecurityClient RequestJSON‑RPC MessageSession Token,Context ID &Auth TokenTLS EncryptionAuthentication& AuthorizationToken ValidationAccess ControlSecure Processing

Error Handling

MCP integrates robust error handling mechanisms to ensure reliable interactions even in complex, stateful sessions.

Error Handling Sequence Diagram

[Persistent Error]alt[Recovery Successful][Success Scenario]alt[Error Scenario]123456Function call request (with session token)Error ResponseRetry with Error Handling StrategySuccess ResponseEscalated Error With DiagnosticsSuccess Response with Updated StateError Code, Message & Recovery HintsClientServerClientServer

Tools, Prompts, and Resources

MCP differentiates among three types of operations:

OperationsRequiresProvidesReturnsMCP Server⚙️ Tool OperationsSide Effectscreate, update,delete⚙️ PromptsNo Side Effectstemplates, guidance⚙️ ResourcesRead-Onlydata access, queryExplicitConfirmationAction GuidanceData Only

Comparisons to REST/GraphQL

IntegrationCommunicationMCPREST/GraphQLStatelessResource-centricFixed EndpointsStatefulOperation-centricDynamic ToolsREST: One-way HTTPGraphQL:Query-focusedMCP: Bidirectionalwith ContextREST/GraphQL: StaticIntegrationMCP: RuntimeExtension

Conclusion

MCP represents a significant evolution from static, one‑off API integrations to dynamic, stateful connections that adapt in real time. Its three‑element architecture, comprising the client, server, and protocol, enables advanced features like dynamic tool integration and context‑aware interactions that standard JSON‑RPC cannot support due to its stateless nature.

Implementation BenefitsImplementation BenefitsKey CapabilitiesKey CapabilitiesMCP ProtocolStatefulCommunicationDynamic ToolIntegrationContext-AwareInteractionsReal-timeAdaptabilityEnhancedSecurityErrorResilienceOperationalFlexibility

While MCP may not yet be as mature as REST or GraphQL, its enhancements, especially in state management, security, error handling, and bidirectional communication, position it as a promising protocol for the future of agentic AI integration.

Organisations must balance their dynamic capabilities against the technology’s increased complexity and evolving maturity.

aimcp