Arrange Act Assert

Jag Reehals thinking 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 Components

Stateful
Bidirectional
Communication

Client
(Requests & Callbacks)

Protocol Layer
(JSON-RPC 2.0+)

Server
(Tools & Resources)

Session
Tokens

Context
IDs

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

ServerClientServerClientSession InitializationStateful Interactionalt[Context Valid][Context Invalid]Initiate Connection (JSON‑RPC Request)1Respond with Session Token & Context ID2Request with Session Token & Context ID3Response with Updated Context4Follow-up Request (with updated context)5Final Result (context-aware)6Error: Invalid Context7

Security

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

Security Layers Diagram

Embedded Security

Client Request

JSON‑RPC Message

Session Token,
Context ID &
Auth Token

TLS Encryption

Authentication
& Authorization

Token Validation

Access Control

Secure Processing

Error Handling

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

Error Handling Sequence Diagram

ServerClientServerClientError Code, Message & Recovery Hintsalt[Recovery Successful][Persistent Error]alt[Error Scenario][Success Scenario]Function call request (with session token)1Error Response2Retry with Error Handling Strategy3Success Response4Escalated Error With Diagnostics5Success Response with Updated State6

Tools, Prompts, and Resources

MCP differentiates among three types of operations:

Operations

Requires

Provides

Returns

MCP Server

⚙️ Tool Operations
Side Effects
create, update, delete

⚙️ Prompts
No Side Effects
templates, guidance

⚙️ Resources
Read-Only
data access, query

Explicit Confirmation

Action Guidance

Data Only

Comparisons to REST/GraphQL

Integration

REST/GraphQL: Static Integration

MCP: Runtime Extension

Communication

REST: One-way HTTP

GraphQL: Query-focused

MCP: Bidirectional with Context

MCP

Stateful

Operation-centric

Dynamic Tools

REST/GraphQL

Stateless

Resource-centric

Fixed Endpoints

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 Benefits

Key Capabilities

MCP Protocol

Stateful
Communication

Dynamic Tool
Integration

Context-Aware
Interactions

Real-time
Adaptability

Enhanced
Security

Error
Resilience

Operational
Flexibility

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.

ai mcp