# How the MCP Server Integrates with AI Assistants for Knowledge Base Access

> Discover how the MCP server integrates with AI assistants to provide queryable knowledge base access to the Maths-CS-AI Compendium using JSON-RPC.

- Repository: [Henry Ndubuaku/maths-cs-ai-compendium](https://github.com/HenryNdubuaku/maths-cs-ai-compendium)
- Tags: how-to-guide
- Published: 2026-07-16

---

**The Maths-CS-AI Compendium implements a Model Context Protocol (MCP) server that exposes the repository's educational content as a queryable knowledge base, allowing AI assistants to search, retrieve, and recommend sections via JSON-RPC calls over STDIO transport.**

The Maths-CS-AI Compendium transforms static markdown documentation into an interactive knowledge base through a dedicated MCP server. Built on the official `@modelcontextprotocol/sdk`, this integration enables any Model Context Protocol-compatible AI assistant to programmatically access mathematical and computer science educational content. The server dynamically indexes repository contents without hard-coded references, ensuring AI assistants always retrieve the latest material.

## Architecture Overview

The MCP server architecture centers on creating an `McpServer` instance configured with a **STDIO transport** layer. In [`mcp/src/index.ts`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/mcp/src/index.ts), the server initializes by importing the SDK and establishing communication over standard input/output streams, which serves as the default channel for AI assistant integrations such as Claude Code, Cursor, and VS Code extensions.

### STDIO Transport Configuration

The STDIO transport enables bidirectional JSON-RPC communication between the AI assistant host and the knowledge base. This approach allows the assistant to spawn the server as a background process and issue tool calls through standard streams, eliminating the need for network sockets or HTTP endpoints.

### Tool Registration and Schema Validation

Each knowledge base operation registers as a **tool** with strict input validation using **Zod schemas**. The server defines tool names, descriptions, and parameter schemas, then attaches handler functions that execute file system operations or text searches.

## Knowledge Base Tools and Capabilities

The server exposes five primary tools that AI assistants invoke to navigate the compendium:

- **list_topics**: Enumerates chapters and sections by reading directory structures from `chapter XX:` folders
- **read_section**: Retrieves full markdown content for specific chapter and section combinations
- **search**: Performs full-text queries across all markdown files with excerpt generation
- **recommend**: Scores section relevance using the [`llms.txt`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/llms.txt) metadata file for personalized learning paths
- **get_examples**: Extracts fenced code blocks filtered by programming language or topic

### Dynamic Content Discovery

Unlike static API endpoints, the `list_topics` tool uses `readdir` operations to discover chapters dynamically. When new folders following the `chapter XX:` naming convention appear in the repository, they become immediately available to AI assistants without server restarts or recompilation.

### Metadata-Driven Recommendations

The `recommend` tool parses the repository's [`llms.txt`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/llms.txt) file to score content relevance. This keyword-matching algorithm returns ordered section suggestions based on the user's learning goals, enabling AI assistants to function as personalized study guides.

## Integration Implementation Examples

AI assistants and external applications integrate with the server through STDIO-based JSON-RPC calls.

### Programmatic Client Setup

The following Node.js example demonstrates spawning the server and calling knowledge base tools:

```javascript
import { spawn } from 'node:child_process';
import { McpClient } from '@modelcontextprotocol/sdk/client/mcp.js';

// Start the MCP server process
const mcpProcess = spawn('npm', ['run', 'start'], { 
  cwd: '/path/to/maths-cs-ai-compendium/mcp' 
});

// Configure STDIO transport
const client = new McpClient({
  transport: {
    send: (msg) => mcpProcess.stdin.write(JSON.stringify(msg) + '\n'),
    onMessage: (handler) => {
      let buffer = '';
      mcpProcess.stdout.on('data', (data) => {
        buffer += data.toString();
        const lines = buffer.split('\n');
        while (lines.length > 1) {
          const line = lines.shift();
          if (line.trim()) handler(JSON.parse(line));
        }
        buffer = lines[0];
      });
    },
  },
});

// Query the knowledge base
await client.callTool('list_topics', { chapter: 5 });
await client.callTool('search', { query: 'attention mechanism' });

```

### Command Line Interface Access

For terminal-based workflows, the SDK provides a CLI wrapper:

```bash

# Start server in background

npm run start --workspace=mcp &

# Execute knowledge base queries

npx @modelcontextprotocol/sdk mcp call list_topics '{"chapter":2}'
npx @modelcontextprotocol/sdk mcp call read_section '{"chapter":7,"section":3}'

```

## Core Implementation Files

The integration relies on specific source files that handle protocol implementation and content indexing:

- **[`mcp/src/index.ts`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/mcp/src/index.ts)**: Contains the `McpServer` instantiation, tool registration logic, and STDIO transport initialization
- **[`mcp/package.json`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/mcp/package.json)**: Declares the `@modelcontextprotocol/sdk` dependency and Zod for schema validation
- **[`llms.txt`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/llms.txt)**: Provides human-curated metadata used by the recommendation engine to score content relevance
- **[`README.md`](https://github.com/HenryNdubuaku/maths-cs-ai-compendium/blob/main/README.md)**: Documents the MCP server setup and knowledge base capabilities for AI assistant developers

## Summary

- The Maths-CS-AI Compendium exposes educational content through an MCP server using STDIO transport for universal AI assistant compatibility
- Five specialized tools enable listing, reading, searching, recommending, and extracting code examples from the repository
- File-system introspection eliminates the need for hard-coded indexes, ensuring content stays synchronized with the repository
- Zod schemas enforce type safety for all AI assistant queries, preventing malformed requests
- Integration requires only Node.js ≥20 and standard JSON-RPC communication over standard streams

## Frequently Asked Questions

### What is the Model Context Protocol (MCP)?

The Model Context Protocol is an open standard that enables AI assistants to connect with external data sources and tools through a standardized JSON-RPC interface. It allows AI systems to query knowledge bases, execute functions, and retrieve contextual information using structured tool definitions.

### How does the server handle new content added to the repository?

The server uses runtime file-system introspection via `readdir` and `readFile` operations rather than static indexes. When new chapters or sections appear in the `chapter XX:` folder structure, the `list_topics` and `search` tools automatically include them in subsequent queries without requiring server restarts.

### Which AI assistants can connect to this MCP server?

Any AI assistant or IDE extension that implements the Model Context Protocol specification can integrate with this server. This includes Claude Code, Cursor, and VS Code extensions that support MCP STDIO transport, allowing them to treat the compendium as a native knowledge source.

### What programming languages are supported for code example extraction?

The `get_examples` tool accepts an optional `language` parameter that filters fenced code blocks by syntax identifier. This supports any language embedded in the repository's markdown files, including Python, JavaScript, TypeScript, Rust, and mathematical notation blocks.