MCP Server Metadata Synchronization: Context Management Strategies for Developer Productivity
As the integration between AI agents and developer tooling deepens, we are automating our blog system through the Model Context Protocol (MCP). However, one nagging issue remains: the ’token waste’ phenomenon where we have to repeatedly explain the project’s structure and context in every session with the AI.
As mentioned in the latest Hacker News post, Stop wasting tokens and re explaining your project between sessions, maintaining project context consistently goes beyond mere convenience; it directly impacts cost-effectiveness.
In this post, we propose a practical design for how to efficiently share dynamic metadata (context) with agents, moving beyond the static resources (Tools, Resources, Prompts) provided by the MCP server.
Problem Definition: The “My Project Introduction” Repetition
Existing MCP clients understand functionality through the tools list provided by the server. For instance, if there’s a write_post tool, Claude will call it to write a post. However, Claude doesn’t know the context, such as “What is the writing style of this blog?” or “What are the latest trends?”
Ultimately, the user has to provide prompts like this every time:
“Write a blog post. The style should be technical and specific, and it should refer to the latest Hacker News trends.”
This leads to unnecessary token consumption. To solve this, we can consider integrating the project’s ‘architecture design document’ or ‘development guidelines’ as resources within the MCP server.
Solution: Resource-Based Metadata Provision
In the MCP specification, Resources are data snippets provided by the server. We can utilize these not just for simple file lookups, but as a ‘project state machine’.
1. Automating Architecture Documentation
Documents like the previously written [ZeroClaw] Codebase Architecture Analysis or [Multi-Agent] File-Based Architecture Design might exist as static files or be scattered across platforms like Confluence. We can make it so that the MCP server loads these into memory upon startup or generates them dynamically for provision.
2. Rust Implementation Example
Let’s write code to add a architecture_guide resource to an MCP server written in Rust (e.g., blog-api-server).
use jsonrpc_core::{Result, Params};
use std::collections::HashMap;
use serde_json::Value;
// A hypothetical MCP handler struct
pub struct BlogMcpServer {
// Cached metadata
cached_context: String,
}
impl BlogMcpServer {
pub fn new() -> Self {
// Load core context (architecture, rules) during server initialization
let context = r#"
Project: ZeroClaw Multi-Agent Runtime
Architecture: Asynchronous multi-agent system using a file-based event bus.
Key Rules:
1. All agents run in independent threads.
2. Communication follows the JSON-RPC over MCP protocol.
3. Logs must be output in structured JSON format.
"#;
Self { cached_context: context.to_string() }
}
// MCP resource read handler (resources/read)
pub fn handle_read_resource(&self, params: Params) -> Result<Value> {
let params_obj: HashMap<String, Value> = params.parse()?;
let uri = params_obj.get("uri").and_then(|v| v.as_str()).unwrap_or("");
match uri {
"context://architecture/guide" => {
// Return cached context when requested by the client
Ok(json!({
"contents": [
{
"uri": uri,
"mimeType": "text/plain",
"text": self.cached_context.clone()
}
]
}))
},
"context://trends/latest" => {
// Fetch and provide external RSS (Hacker News, etc.) in real-time (dynamic resource)
let trends = fetch_latest_hn_trends().await.unwrap_or_default();
Ok(json!({
"contents": [{
"uri": uri,
"mimeType": "application/json",
"text": trends
}]
}))
},
_ => Err(Error::invalid_params("Unknown resource URI"))
}
}
}
async fn fetch_latest_hn_trends() -> Option<String> {
// In reality, you would use reqwest etc. to parse RSS
// Returning a simple JSON string for demonstration
Some(r#"[{"title": "JSON-LD Explained", "link": "..."}]"#.to_string())
}
This code allows the MCP client to instantly retrieve the predefined project architecture rules by requesting the resource with the URI context://architecture/guide.
3. Automatic Prompt Injection
To prevent clients (like Claude) from requiring complex configurations, we can leverage the MCP server’s Prompts functionality to provide templates that automatically complete system prompts.
The MCP server can expose prompt templates like this:
Prompt Name: generate_blog_post
Arguments: topic, tone
{
"name": "generate_blog_post",
"description": "Creates a technical blog post based on architecture context and latest trends.",
"arguments": [
{ "name": "topic", "description": "Main topic", "required": true },
{ "name": "tone", "description": "Writing style", "required": false }
]
}
The actual implementation logic (in Rust) would work as follows:
pub fn handle_get_prompt(&self, params: Params) -> Result<Value> {
let name = params.get("name").and_then(|v| v.as_str()).unwrap_or("");
let args = params.get("arguments").and_then(|v| v.as_object()).unwrap_or(&json!(null));
if name == "generate_blog_post" {
let topic = args.get("topic").unwrap_or(&json!("general"));
// Inject the architecture guide fetched from resources into the prompt
let system_instruction = format!(
"You are writing for a blog defined by the following architecture:\n{}\n\nPlease write a post about: {}",
self.cached_context, // Architecture information loaded earlier
topic
);
Ok(json!({
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": system_instruction
}
}
]
}))
} else {
Err(Error::invalid_params("Unknown prompt"))
}
}
Effects and Expected Outcomes
The core of this approach is ‘duplication’. Similar to the Hacker News article Prefer duplication over the wrong abstraction, we avoid complex abstractions to simplify the essence of the project. Instead, we copy (duplicate) the necessary information (context) to where it’s needed (prompt).
- Maintain Consistency: When documents are updated, simply restarting the MCP server or refreshing resources will ensure all sessions reflect the latest information.
- Token Savings: Users no longer need to repeatedly explain, “My project is a multi-agent system built with Rust…”
- Automation-Friendly: If documents are automatically generated and registered as MCP resources within a CI/CD pipeline, AI can always generate or review code based on the latest documentation.
Conclusion
We must utilize documents like the [ZeroClaw] Multi-Agent Architecture Design not just as ‘reading material,’ but as executable AI brains (context). Adding this metadata synchronization layer to the MCP server is the first step towards building complex LLM applications, and it lays the foundation for developers to focus on essential logic without wasting tokens.
In the next post, we will discuss how this metadata is actually utilized in the communication architecture of team agents like Claude Code.