Skip to content

Project: [Creative Apps] - Code Intelligence MCP Server #130

@ANcpLua

Description

@ANcpLua

Track

Creative Apps (GitHub Copilot)

Project Name

Code Intelligence MCP Server

GitHub Username

@ANcpLua

Repository URL

https://github.com/ANcpLua/agentsleague-starter-kits

Project Description

Code Intelligence MCP is an MCP server that gives GitHub Copilot six AI-powered tools for understanding code. It connects to Copilot Chat via the Model Context Protocol and exposes tools that analyze, convert, and visualize source code — all powered by GitHub Models free tier with zero Azure spend.

The six tools:

  1. ExplainCode — Analyzes source code to identify algorithms, assess Big-O complexity, detect bugs, and suggest improvements. Returns structured markdown analysis.

  2. ConvertCode — Converts code between any two programming languages with idiomatic target-language patterns and naming conventions.

  3. SolveWithCode — Takes a natural language problem description and generates parameterized, runnable code with input validation and usage examples.

  4. AnalyzeVisual — Reviews text descriptions of UI designs (ASCII mockups, design specs) for accessibility, layout analysis, and implementation guidance.

  5. GenerateArchitectureDiagram — Scans a real codebase directory, selects files within a character budget, generates Mermaid architecture diagrams, detects and fixes subgraph name collisions, and produces clickable mermaid.live editor links.

  6. ExplainTrace — Transforms raw OpenTelemetry span JSON into human-readable narratives explaining what happened, what was slow, and what to fix.

Every tool call is self-instrumented with OpenTelemetry using gen_ai semantic convention attributes. The tool that explains code also explains itself.

Demo Video or Screenshots

Demo Video: (will be added shortly)

Primary Programming Language

C#

Key Technologies Used

  • .NET 10 — Latest runtime with C# 14
  • ModelContextProtocol SDK (ModelContextProtocol NuGet v1.0.0) — MCP server implementation with stdio transport
  • Microsoft.Extensions.AI — Model-agnostic IChatClient abstraction for swappable LLM backends
  • GitHub Models (gpt-4o-mini) — Free-tier LLM inference via https://models.inference.ai.azure.com
  • OpenTelemetry — Self-instrumentation with OTLP export for every tool call
  • Microsoft.Extensions.FileSystemGlobbing — File scanning with glob-based inclusion/exclusion patterns
  • GitHub Copilot — AI-assisted development (Agent Mode, Chat, Inline Suggestions, Plan Mode)

Submission Type

Individual

Team Members

No response

Submission Requirements

  • My project meets the track-specific challenge requirements
  • My repository includes a comprehensive README.md with setup instructions
  • My code does not contain hardcoded API keys or secrets
  • I have included demo materials (video or screenshots)
  • My project is my own work with proper attribution for any third-party code
  • I agree to the Code of Conduct
  • I have read and agree to the Disclaimer
  • My submission does NOT contain any confidential, proprietary, or sensitive information
  • I confirm I have the rights to submit this content and grant the necessary licenses

Quick Setup Summary

  1. Clone the repo: git clone https://github.com/ANcpLua/agentsleague-starter-kits.git
  2. Navigate to the project: cd track-1-creative-apps/src/CodeIntelligenceMcp
  3. Set your GitHub token: export GITHUB_TOKEN="your-github-pat"
  4. Build: dotnet build
  5. Run: dotnet run
  6. In VS Code, add the MCP server to .vscode/mcp.json (see README) and use Copilot Chat

Requires: .NET 10 SDK, GitHub personal access token (free tier). No Azure spend required.

Technical Highlights

1. Architecture Diagram Generator with Mermaid
The standout feature. It scans a real codebase directory using glob patterns, selects files within a configurable character budget (default 500K), sends them to the LLM, and generates a Mermaid architecture diagram. It then detects subgraph name collisions (which cause Mermaid rendering errors) and fixes them automatically. The output includes clickable mermaid.live View and Edit links using zlib compression and base64url encoding to match the mermaid.live URL format.

2. Six Tools in One MCP Server
Following the MCP pattern of grouping related tools in a single server. All six tools are discovered by Copilot via one server.json config. Adding a new tool is one method with [McpServerTool] — no extra registration needed.

3. OTel Self-Instrumentation
Every tool call emits its own OpenTelemetry span with gen_ai.operation.name, gen_ai.request.model, and gen_ai.usage.output_tokens attributes. The MCP server that helps users understand OTel traces is itself observable via OTel.

4. IChatClient Abstraction
All tools use Microsoft.Extensions.AI's IChatClient interface. The model provider (GitHub Models) is configured once in Program.cs via DI. Swapping to Azure OpenAI or Ollama is a one-line DI change.

5. Mermaid Pipeline
The diagram generation has a full pipeline: FileScanner (glob-based discovery) → TokenBudgeter (character budget selection) → PromptBuilder (LLM prompt construction) → DiagramGenerator (IChatClient call) → DiagramFormatter (Mermaid extraction, cycle fix, link generation). Each stage is a separate class with a single responsibility.

Challenges & Learnings

Mermaid Subgraph Name Collisions: LLMs frequently generate Mermaid diagrams where a subgraph and a node inside it share the same identifier, causing rendering failures. I built the CycleDetector to parse the Mermaid syntax, detect these collisions, and rename the conflicting subgraph by appending an underscore. This was the trickiest parsing problem in the project.

Character Budgeting for Large Codebases: When scanning repositories with thousands of files, sending everything to the LLM exceeds context windows. The TokenBudgeter iterates through scanned files and accumulates content until the character budget is reached, skipping files that would exceed it. This produces useful diagrams even for very large projects.

MCP Protocol stdio Transport: Logs must go to stderr, not stdout, because stdout is reserved for the MCP JSON-RPC protocol. Getting this wrong causes the MCP client to fail silently. The fix is builder.Logging.AddConsole(o => o.LogToStandardErrorThreshold = LogLevel.Trace).

Key Learnings:

  • MCP servers are the right abstraction for extending Copilot — they compose naturally with Copilot's reasoning
  • GitHub Models free tier is surprisingly capable for tool-based workflows
  • The Microsoft.Extensions.AI abstraction pays for itself immediately when you want to test with different models
  • Self-instrumentation creates a compelling demo narrative: "the tool explains itself"

Contact Information

anfh22@outlook.com

Country/Region

Austria

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions