Mcp server development

From Hack23/riksdagsmonitor · View interactive version

Mcp server development is an AI agent skill from the GitHub repository Hack23/riksdagsmonitor. Model Context Protocol server development, MCP tool patterns, MCP configuration best practices, GitHub MCP integration

How to use this skill

Skill file

MCP Server Development Skill

πŸ”΄ AI FIRST Quality Principle

Apply the AI FIRST principle: never accept first-pass quality. Minimum 2 iterations. Read all output, improve every section. No shortcuts.

Purpose

Guide the development and configuration of Model Context Protocol (MCP) servers for the Riksdagsmonitor platform, enabling AI-powered tooling integration with GitHub Copilot and other MCP-compatible clients.

When to Use

Do NOT use for:

MCP Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  MCP Client     │────▢│  MCP Server  │────▢│  Data Sources   β”‚
β”‚  (Copilot/IDE)  │◀────│  (Tools)     │◀────│  (Riksdag API)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                       β”‚
        β”‚ JSON-RPC 2.0         β”‚ Tool Definitions
        β”‚ over stdio/SSE       β”‚ Input/Output Schemas

MCP Configuration Best Practices

GitHub Copilot MCP Config

{
  "mcpServers": {
    "cia-political-data": {
      "type": "stdio",
      "command": "node",
      "args": ["dist/mcp-server.js"],
      "env": {
        "CIA_DATA_DIR": "${workspaceFolder}/data"
      }
    }
  }
}

Key Configuration Rules

  1. Never embed secrets in copilot-mcp-config.json β€” use environment references
  2. Scope tools narrowly β€” each tool should do one thing well
  3. Validate all inputs against JSON Schema before processing
  4. Return structured data β€” prefer typed objects over free-form strings
  5. Include error details in tool responses for debugging

MCP Tool Design Patterns

Tool Definition Schema

interface McpToolDefinition {
  name: string;           // e.g., "get_politician_votes"
  description: string;    // Clear, concise purpose
  inputSchema: {
    type: "object";
    properties: Record<string, JsonSchema>;
    required: string[];
  };
}

CIA-Specific Tool Examples

// Politician lookup tool
const getPoliticianTool = {
  name: "get_politician_profile",
  description: "Retrieve profile and voting record for a Swedish Parliament member",
  inputSchema: {
    type: "object",
    properties: {
      personId: { type: "string", description: "Riksdagen person ID" },
      includeVotes: { type: "boolean", default: false }
    },
    required: ["personId"]
  }
};

// Document search tool
const searchDocumentsTool = {
  name: "search_riksdag_documents",
  description: "Search Swedish Parliament documents by keyword, type, and date range",
  inputSchema: {
    type: "object",
    properties: {
      query: { type: "string" },
      docType: { type: "string", enum: ["motion", "proposition", "betankande"] },
      fromDate: { type: "string", format: "date" },
      toDate: { type: "string", format: "date" }
    },
    required: ["query"]
  }
};

Error Handling Pattern

async function handleToolCall(name: string, args: unknown): Promise<McpResult> {
  try {
    const validated = validateInput(name, args);
    const result = await executeQuery(validated);
    return { content: [{ type: "text", text: JSON.stringify(result) }] };
  } catch (error) {
    return {
      content: [{ type: "text", text: `Error: ${error.message}` }],
      isError: true
    };
  }
}

GitHub MCP Integration

Available GitHub MCP Tools

The CIA project uses GitHub MCP server for:

Best Practices for GitHub MCP

  1. Use specific queries β€” avoid broad searches that return too many results
  2. Paginate results β€” always handle pagination for large result sets
  3. Cache responses β€” reduce API calls for frequently accessed data
  4. Handle rate limits β€” implement exponential backoff

Security Considerations

ISMS Alignment

| Control | Requirement |

|---------|-------------|

| ISO 27001 A.8.9 | Configuration management for MCP servers |

| NIST CSF PR.DS-2 | Data-in-transit protection for MCP transport |

| CIS Control 16 | Application software security for MCP tools |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.