微软。模板引擎。主控程序
允许AI代理使用的MCP服务器 dotnet new 模板——通过自然对话搜索、检查、预览和创建项目,而不是记住CLI标志。
取而代之的是:
dotnet new list --language C#
dotnet new webapi --help
dotnet new webapi --auth Individual --use-controllers --name MyApi --output ./MyApi你的AI代理只是说: *“我需要一个带有身份验证和控制器的web API”* --MCP服务器计算出其余部分。
作者模板验证
创建自定义 dotnet new 模板? template_validate 发现错误 之前 你发表——不再猜测你的 template.json 正确:
Agent calls: template_validate("./my-template")
← Returns:
{
"valid": false,
"summary": "2 error(s), 1 warning(s), 3 suggestion(s)",
"errors": [
"Missing required field 'shortName'.",
"Parameter 'Framework': default value 'net7.0' is not in the choices list."
],
"warnings": [
"Missing 'sourceName'. Without it, the generated project name won't be customizable via --name."
],
"suggestions": [
"Consider adding a 'description' field to help users understand what this template creates.",
"Consider adding 'language' tag (e.g., 'C#') for better discoverability.",
"Consider adding 'type' tag (e.g., 'project', 'item') for filtering."
]
}它捕获了什么: 缺少必填字段、无效的标识格式、短名称与CLI命令冲突、参数问题(缺少默认值、空选项、前缀冲突、类型不匹配)、计算符号损坏、约束配置错误和缺少标记。
没有现有的工具可以做到这一点——大多数模板作者只有在以下情况下才会发现问题 dotnet new install 失败或产生错误的输出。
工具
| 工具 | 它做什么 |
|---|---|
template_search | 本地搜索 和 在NuGet.org上--一个电话,排名结果 |
template_list | 列出已安装的内容,按语言/类型/分类进行筛选 |
template_inspect | 参数、约束、后期操作——一次完成 |
template_instantiate | 创建一个项目。未安装?自动从NuGet解析。以交互方式诱导缺失的参数 |
template_dry_run | 无需触摸磁盘即可预览文件 |
template_install | 安装一个包(幂等--如果已经存在则跳过) |
template_uninstall | 删除模板包 |
templates_installed | 所有已安装设备的清单 |
template_from_intent | *“带有auth的web API”* →webapi+ auth=Individual --无需法学硕士 |
template_create_from_existing | 分析.csproj→ 生成符合仓库约定的可重用模板 |
template_compose | 在一个工作流中执行一系列模板(项目+项目) |
template_suggest_parameters | 基于交叉参数关系,建议具有基本原理的参数值 |
template_validate | 发布前验证本地模板目录是否存在创作问题 |
template_compare | 并排比较2个以上的模板——参数、功能、框架 |
solution_analyze | 分析解决方案/工作空间——项目结构、框架、CPM状态 |
📖 完整工具参考→
托管部署
托管部署可在 Frontier AI.
快速开始
全局工具(.NET 8+)
dotnet tool install --global DotnetTemplateMCP --version 1.3.0零安装 dnx (.NET 10+)
dnx -y DotnetTemplateMCP --version 1.3.0VS代码/GitHub副本
添加 mcp.json:
{
"servers": {
"dotnet-templates": {
"type": "stdio",
"command": "dnx",
"args": ["-y", "DotnetTemplateMCP", "--version", "1.3.0"]
}
}
}运输方式
标准(默认)
用于本地CLI和工具使用的标准I/O传输:
template-engine-mcp # stdio is the default
template-engine-mcp --transport stdio # explicitHTTP(远程/云/团队共享)
用于远程、多租户或CI/CD部署的流式HTTP传输:
template-engine-mcp --transport http
# or via environment variable:
MCP_TEMPLATE_TRANSPORT=http template-engine-mcpHTTP服务器公开:
/mcp--MCP可流式传输HTTP端点/health--健康检查端点
配置侦听URL:
MCP_TEMPLATE_HTTP_URL=http://0.0.0.0:8080 template-engine-mcp --transport http连接您的MCP客户端:
{
"servers": {
"dotnet-templates": {
"type": "http",
"url": "http://localhost:5005/mcp"
}
}
}互动启发
当模板具有未提供的所需参数时,服务器 以交互方式询问用户 通过MCP激发,而不是失败。模板参数类型映射到表单字段:
| 模板参数 | 引用字段 |
|---|---|
string | 文本输入 |
bool / boolean | 复选框 |
int / number | 数字输入 |
| 选择参数 | 单选下拉列表 |
禁用 MCP_TEMPLATE_ELICITATION=false.
运作原理
You: "I need a web API with authentication, controllers, and Docker support"
→ template_from_intent extracts keywords: web api, authentication, controllers, docker
→ Matches: webapi (confidence: 0.85)
→ Resolves: auth=Individual, UseControllers=true, EnableDocker=true
→ template_instantiate creates the project服务器也可以 智能默认值 (AOT → 最新框架,auth→ HTTPS保持开启), 参数验证 在写入文件之前, 约束检查 (操作系统、SDK、工作负载), 互动启发 缺少所需参数,以及 自动解析 如果未安装NuGet中的模板。
CPM和最新软件包版本
在使用的解决方案中创建项目时 中央包管理,服务器自动:
- 发现
Directory.Packages.props沿着目录树向上走 - 条带
Version生成的属性.csproj包引用 - 增加 缺失 `
条目到 Directory.Packages.props`
- 解决 最新稳定的NuGet版本——不再有模板中过时的硬编码版本
Before (what dotnet new generates):
← stale, breaks CPM
After (what template_instantiate produces):
.csproj:
Directory.Packages.props:
也适用于独立项目——版本直接在 .csproj.
多模板组合
在一次调用中链接多个模板 template_compose:
[
{"templateName": "webapi", "name": "MyApi", "parametersJson": "{\"auth\": \"Individual\"}"},
{"templateName": "gitignore", "target": "."}
]📖 架构和智能行为→
工具配置文件(精简版与完整版)
默认情况下,所有14个工具都可用。如果您的代理使用更少的工具工作得更好,请设置 MCP_TEMPLATE_TOOL_PROFILE 环境变量:
| 配置文件 | 工具 | 何时使用 |
|---|---|---|
full (默认) | 全部14个工具 | 完全控制--高级工作流、合成、自定义模板 |
lite | 5个核心工具 | 只需要查找和创建项目的更简单的代理 |
Lite配置文件工具: template_from_intent, template_instantiate, template_inspect, template_search, template_dry_run
{
"servers": {
"dotnet-template-mcp": {
"command": "dotnet-template-mcp",
"env": {
"MCP_TEMPLATE_TOOL_PROFILE": "lite"
}
}
}
}非精简版工具将返回一条有用的消息,解释它们已被禁用以及如何启用它们。
文档
| 医生 | 里面有什么 |
|---|---|
| 配置 | VS Code、克劳德桌面、光标设置+故障排除 |
| 工具参考 | 每个工具的参数、类型和示例 |
| 建筑 | 模板缓存、智能行为、遥测、项目结构 |
| MCP vs技能 | 为什么MCP优于副驾驶技能——利与弊 |
| 普通LLM与MCP | 并列:普通LLM与MCP工具的区别(4种情况) |
| 技能等价物 | 用技能来弥补这一点需要什么 |
建筑与测试
dotnet build
dotnet test # 185+ tests — unit, integration, and E2ECI通过推送/PR运行 (Ubuntu+Windows)。
贡献
欢迎投稿!请在提交PR之前打开一个问题来讨论拟议的更改。
# Setup
dotnet restore
dotnet build
# Run tests
dotnet test
# Pack locally
dotnet pack src/Microsoft.TemplateEngine.MCP -o nupkg/更新日志
看 更改日志.md 发布历史。
