[Home](../../) › [Metalama](../../metalama) › [Features](../features.md) › [Productivity Features](productivity.md) › AI Coding Agents

# AI Coding Agents

> The free Metalama MCP server lets AI coding agents query the code model of any C# project or solution, the Metalama plugin gives them the documentation and the API reference, and the command-line tool shows them the transformed code and the applied aspects, so they write aspects from facts instead of guesses.

Canonical: https://postsharp.net/metalama/features/ai-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.

```powershell
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 preview`** prints 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 introspect`** answers 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 the `MetalamaWriteIntrospectionFile` MSBuild property is set. It requires no license, and it requires Metalama 2027.0.7-preview or later.

```powershell
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:
  - [Using the MCP server](https://doc.postsharp.net/metalama/preview/conceptual/introspection/mcp-server)
  - [Configuring AI agents](https://doc.postsharp.net/metalama/preview/conceptual/using/ide/ai-agents)
* Blog post: [Query Any .NET Codebase from Your AI Agent with the Metalama MCP Server](https://postsharp.net/blog/metalama-mcp-server)
* Related: [Code Query API](https://postsharp.net/metalama/features/code-query)

---

## Site navigation

- Previous: [Visual Studio Tooling](tooling.md)
- Next: [Test Frameworks](testing.md)
- Index of the whole site: [llms.txt](../../llms.txt)

