AI Coding Agents
An AI coding agent that explores a C# codebase with text search guesses at inheritance, references and generated code. Metalama gives it the compiler’s view instead: a free MCP server that answers questions from the semantic model, a plugin that puts the Metalama documentation within reach, and command-line tools that show the transformed code and the aspects applied to it.
Metalama MCP server
The Metalama MCP server loads your .csproj, .sln, .slnx or .slnf files with MSBuild and Roslyn, and exposes them through the same code model that Metalama aspects and fabrics use. Your projects don’t need to reference Metalama.
- Answers from the semantic model. The agent writes C# queries over types, members, inheritance and references, such as the types that implement an interface through a base class, which no text search can give.
- Loaded once. The workspace stays in memory, so follow-up queries take milliseconds.
- Aspects and transformed code. In a project that uses Metalama, the agent also sees the aspect instances, the advice they add, and the transformed code that compiles.
- An interactive view for you. Results open in a LINQPad-style HTML page where you sort, filter, expand declarations, jump to the source, and edit and rerun the query.
- Free and open source. It works with any agent that supports MCP, such as Claude Code, GitHub Copilot and Cursor.
dotnet tool install -g Metalama.Mcp
claude mcp add metalama -- metalama-mcp
Metalama plugin
The Metalama plugin for Claude Code and OpenAI Codex gives the agent the conceptual documentation, the API reference, the commented examples and the pattern libraries’ documentation. The agent looks up the real API instead of inventing one.
Command-line tools
An agent cannot open the Visual Studio tooling, so the Metalama command-line tool gives it the same answers in the terminal:
metalama previewprints the transformed code of one or a few files, without building the whole project. The agent checks the code that an aspect generates after each change to the aspect or to its target.metalama introspectanswers questions such as “which aspects apply to this method, and what do they change?” without building the project. It reads the introspection file that the last build wrote when theMetalamaWriteIntrospectionFileMSBuild property is set. It requires no license, and it requires Metalama 2027.0.7-preview or later.
dotnet tool install -g metalama.tool --prerelease
metalama preview src/MyProject/Services/OrderService.cs
metalama introspect show declaration src/MyProject/Customer.cs:18
Rules the agent cannot bypass
Aspects and validation rules run in the compiler. Whether a line was written by a developer or by an agent, the same aspects generate the same code, and the same rules report the same errors, at every build.
Resources
- Reference documentation:
- Blog post: Query Any .NET Codebase from Your AI Agent with the Metalama MCP Server
- Related: Code Query API