Concept #81Mediumextended-ai-concepts

Can we use predefined instructions or data given to AI using MCP?

#gen-ai#mcp

Answer

Using Predefined Instructions or Data with AI via MCP

MCP is one of the most powerful ways to provide AI models with persistent, structured instructions and dynamic data beyond simple system prompts.

Approaches Compared

ApproachToolScopeDynamic?
System promptAPI parameterPer-callNo
Config fileCLAUDE.md / GEMINI.mdPer-projectNo
MCP ResourceMCP serverOn demandYes
MCP PromptMCP serverReusable templatesYes
MCP ToolMCP serverData injectionYes

MCP Resources for Static Instructions

python
from mcp.server import Server
import mcp.types as types

app = Server("instructions-server")

@app.list_resources()
async def list_resources():
    return [
        types.Resource(
            uri="docs://coding-standards",
            name="Coding Standards",
            description="Company Python coding standards"
        ),
        types.Resource(
            uri="docs://api-spec",
            name="API Specification",
            description="Internal REST API documentation"
        )
    ]

@app.read_resource()
async def read_resource(uri: str):
    paths = {
        "docs://coding-standards": "docs/coding_standards.md",
        "docs://api-spec": "docs/api_spec.yaml"
    }
    with open(paths[uri]) as f:
        content = f.read()
    return types.ReadResourceResult(
        contents=[types.TextResourceContents(uri=uri, text=content, mimeType="text/plain")]
    )

MCP Prompt Templates

python
@app.list_prompts()
async def list_prompts():
    return [types.Prompt(
        name="code-review",
        description="Standard code review template",
        arguments=[types.PromptArgument(name="language", description="Programming language")]
    )]

@app.get_prompt()
async def get_prompt(name: str, arguments: dict):
    if name == "code-review":
        lang = arguments.get("language", "Python")
        return types.GetPromptResult(messages=[
            types.PromptMessage(
                role="user",
                content=types.TextContent(
                    type="text",
                    text=f"Review this {lang} code for: security, performance, readability, tests coverage"
                )
            )
        ])

Config Files (Simplest Approach)

markdown
# CLAUDE.md (project root — Claude reads automatically)

## Project Context
- FastAPI backend, PostgreSQL database, Redis cache
- All Python code must use type hints and docstrings
- Tests in /tests directory using pytest
- Follow PEP 8

## Coding Rules
- Use async/await for all I/O
- Always handle exceptions explicitly
- Log at DEBUG level for development, INFO for production

## Architecture
- Services in /src/services/
- Models in /src/models/
- Routes in /src/routes/

Layered Instruction Architecture

text
1. CLAUDE.md (always-on project context)
        +
2. System prompt (per-session role/persona)
        +
3. MCP Resources (on-demand detailed docs)
        +
4. MCP Tools (dynamic data from APIs/DBs)
        =
Fully context-aware AI assistant

This layered approach gives you:

  • Persistent project knowledge (CLAUDE.md)
  • Session-specific behavior (system prompt)
  • Rich, current reference data (MCP resources)
  • Real-time data access (MCP tools)