Skip to main content
Glama
nezolder

Civil 3D MCP Server

by nezolder

Civil 3D MCP サーバー — Dynamic Roslyn フォーク

Autodesk Civil 3D 内で AI アシスタントが C# コードを記述・実行できるようにする MCP サーバー。多数の固定ツールの代わりに、AI がタスク固有のコードを生成し、Civil 3D API アクセス付きで実行します。

プロジェクトの範囲と系譜

このフォークは、動的な Roslyn/C# 実行モデルと、3 つの MCP ツールからなる意図的に小さな公開サーフェスを維持しています。現在の互換性ベースラインは Autodesk Civil 3D 2025 で、ローカルでの作業は信頼性、安全性、測定可能な効率性、再利用可能な Civil 3D スキルに焦点を当てています。他の Civil 3D バージョンは、別途検証された互換性作業を通じて後から追加できます。

このプロジェクトは barbosaihan/civil3d-mcp から派生しています。SantosSjba/mcp-to-c3d は、選択されたテスト済みのアイデアについて評価され、Sacred-G/Civil3D-mcp はアーキテクチャの参考としてのみ使用されました。詳細な帰属とライセンスの境界については PROVENANCE.md を参照してください。

この独立したプロジェクトは、Autodesk とは提携しておらず、Autodesk の承認も受けていません。Autodesk アセンブリやその他のプロプライエタリな Civil 3D ファイルは含まれていません。

Related MCP server: Civil 3D MCP Server

アーキテクチャ

┌─────────────────┐     stdio      ┌──────────────────┐     TCP/JSON-RPC    ┌──────────────────┐
│   AI Assistant   │ ◄────────────► │  MCP Server (TS) │ ◄──────────────────► │  Civil 3D Plugin │
│ (Claude, Cline)  │               │   3 meta-tools    │     port 8080       │  Roslyn Engine   │
└─────────────────┘               └──────────────────┘                      └──────────────────┘
                                         │                                         │
                                    Skills Library                           C# Code Execution
                                   (.skill.md files)                      (full Civil 3D API)

3 つのメタツール

ツール

目的

安全性

civil3d_execute

書き込みアクセス付きで C# コードを実行。コミット後のオプション保存あり

⚠️ 図面を変更します

civil3d_query

C# コードを読み取り専用で実行(コミットなし)

✅ 副作用なし

civil3d_skills

コードスキルテンプレートの閲覧・検索・読み取り。api_lookup は読み込み済みの公開 Civil 3D API メタデータを検索します

✅ メタデータのみ

動作の仕組み

  1. AI がスキルを読む → ドキュメント化された C# コードテンプレートを取得

  2. AI がコードを適応させる → パラメータを入力し、パターンを組み合わせる

  3. AI がコードを送信する → civil3d_execute または civil3d_query 経由

  4. Roslyn がコンパイル・実行する → 完全な API アクセス付きで Civil 3D 内で実行

  5. 結果が JSON として返る → AI に戻る

対話の例

User: "What surfaces are in my drawing?"

AI: Uses civil3d_query with:
  var surfaces = new List<object>();
  foreach (ObjectId id in CivilDoc.GetSurfaceIds()) {
    var s = Transaction.GetObject(id, OpenMode.ForRead) as TinSurface;
    surfaces.Add(new { s.Name, s.Layer });
  }
  return surfaces;

Result: [{ "Name": "EG", "Layer": "C-TOPO-EG" }, ...]

スキルライブラリ

civil3d_skills は、読み込み済みの許可リスト登録済み Civil 3D ホストアセンブリから、公開されている型およびメンバー名・シグネチャの限定された読み取り専用検索を行う action: "api_lookup" もサポートしています。アセンブリの読み込み、C# コードの実行、アクティブな図面へのアクセスは行いません。クエリと、必要に応じてアセンブリ、名前空間プレフィックス、結果数の制限を指定します。

スキルは skills/ 内のドキュメント化された C# コードテンプレートです:

skills/
├── surfaces/           # Surface operations
├── alignments/         # Alignment + station/offset
├── points/             # COGO points
├── geometry/           # Lines, polylines, text
├── drawing/            # Drawing info
└── workflows/          # Complex multi-object operations

スクリプトグローバル

civil3d_execute または civil3d_query を介して実行されるコードは、以下にアクセスできます:

グローバル

型

説明

Document

Document

アクティブな AutoCAD ドキュメント

CivilDoc

CivilDocument

アクティブな Civil 3D ドキュメント

Database

Database

ドキュメントデータベース

Transaction

Transaction

アクティブなトランザクション

Editor

Editor

ドキュメントエディタ

すべての Civil 3D 名前空間は自動インポートされます。

civil3d_execute トランザクションをコミットすると開いている図面が変更されますが、それ自体で DWG ファイルがディスクに書き込まれるわけではありません。完了した変更も保存する必要がある場合は、saveDrawing: true を設定します。プラグインはスクリプトのトランザクションとドキュメントロックが閉じられた後にのみ保存します。スクリプトは Database.SaveAs を呼び出したり、QSAVE をキューに入れたりしてはなりません。保存リクエストは別のデフォルト 10 分のタイムアウトを使用し、自動的に再試行されることはありません。

セットアップ

1. MCP サーバーのビルド

npm install && npm run build

2. プラグインのビルド

# Copy DLLs from Civil 3D to C_References/ (see C_References/README.md)
cd plugin/Civil3dMcpPlugin
dotnet build

3. Civil 3D での読み込み

NETLOAD → select Civil3dMcpPlugin.dll
C3DMCPSTATUS → verify running

4. AI の設定

{
  "mcpServers": {
    "civil3d": {
      "command": "node",
      "args": ["/path/to/civil3d-mcp/build/index.js"]
    }
  }
}

環境変数

変数

デフォルト

説明

CIVIL3D_HOST

localhost

プラグインホスト

CIVIL3D_PORT

8080

プラグインポート

CIVIL3D_COMMAND_TIMEOUT

120000

実行タイムアウト(ms)

CIVIL3D_SAVE_TIMEOUT

600000

saveDrawing: true 付きの実行リクエストのタイムアウト(ms)

LOG_LEVEL

info

ログレベル

ベンチマーキング

フェーズ 2A のホスト非依存レコーダー、フェーズ 2A.1 のオプトイン内部ライブトレース契約、およびフェーズ 2A.2 の読み取り専用ライブランナーは、benchmark/README.md に文書化されています。いずれも MCP ツール、キュー、リトライを追加しません。2A.2 ランナーは、明示的に起動された場合にのみ、固定された読み取り専用クエリを呼び出すことができます。

構造化エラー(フェーズ 2B.1)

civil3d_query と civil3d_execute は、既存のテキストエラー内容と isError: true を維持しつつ、スキーマ civil3d-mcp-error/v1 の structuredContent も返します。安定したエラーフィールドは code、category、message、source、outcome、retryable です。コマンドタイムアウトまたは送信後の接続喪失は outcome: "unknown" かつ retryable: false となり、サーバーは自動的に再試行しません。成功レスポンスと 3 ツールの公開サーフェスは変更されません。

プライベート TCP フレーミング(フェーズ 2C.1)

各 localhost TCP 接続は、1 つの UTF-8 JSON-RPC リクエストと 1 つのレスポンスを運びます。各 JSON ボディの後には LF が続き、LF を除く UTF-8 バイトとして 8 MiB に制限されます。Node クライアントは、完全な JSON ボディの後に秩序だった接続クローズが続く場合、以前のプラグインのフレーミングなしレスポンスも引き続き受け入れます。過大なリクエストは書き込まれる前に拒否されます。過大または不正なレスポンス、および中断された接続は、再試行不可の構造化トランスポートエラーを生成します。実行は完了したがプラグインが過大な結果を返せなかった場合、報告される outcome は unknown です。

操作監査ログと書き込み冪等性(フェーズ 2I.1 / 2I.2)

デフォルトの info ログレベルでは、受け入れられた各 civil3d_query および civil3d_execute 操作は、1 つの境界付き stderr 監査イベントを出力します。これには、新しい不透明な操作 ID、ツール名、C# ソースの SHA-256 と UTF-8 バイト長、成功/エラーステータス、経過ミリ秒が含まれます。エラーは安定した code/category/source/outcome フィールドのみを追加します。監査イベントには、呼び出し元のコード、説明、図面 ID、結果、エラーメッセージは決して含まれません。

civil3d_execute は、オプションの不透明な idempotencyKey(1〜128 文字の ASCII 文字、数字、.、_、:、-)も受け入れます。1 つのプラグインセッション内で、キーを UTF-8 C# SHA-256、正規化された expectedDrawing ID、および saveDrawing の選択にバインドします。重複は、進行中、競合、またはコミット済みとして拒否されます。コミット済みエントリは結果を保持しないため、呼び出し元は読み取り専用クエリで調整する必要があります。保存失敗はメモリ内の書き込みコミット後に発生するため、誤った重複変更を防ぐためにキーは完了済みとして保持されます。セッションは最大 256 個の完了済みキーを保持し、最も古いものを決定的に追い出します。これにより、永続化や自動リトライ、正確に 1 回のセマンティクスが追加されることはありません。

セキュリティ

Roslyn サンドボックスは以下をブロックします:

  • プロセス実行(Process.Start)

  • ファイル削除(File.Delete)

  • ネットワークリクエスト(HttpClient、Sockets)

  • レジストリアクセス

  • 動的アセンブリの読み込み

すべての Civil 3D API 操作は許可されています。

この正規表現サンドボックスは多層防御であり、信頼境界ではありません。両方のコードツールは可変の Civil 3D および AutoCAD API オブジェクトを受け取ります。civil3d_query はホストのトランザクションコミットをスキップしますが、任意の動的 C# が副作用なしであることを保証できません。信頼された承認ゲート付きのコードのみを実行してください。ループバック TCP はリモートネットワークアクセスを防ぎますが、他のローカルプロセスを認証しません。

ライセンス

MIT

Available Tools

3 tools
civil3d_executeA

Execute C# code in Civil 3D with write access. The code runs inside a committed transaction. Available globals: Document, CivilDoc, Database, Transaction, Editor. All Civil 3D namespaces are auto-imported. Return a value to get results back as JSON. Use this for operations that MODIFY the drawing (create, edit, delete objects). expectedDrawing must come from a prior read-only identity query. To persist the drawing file, set saveDrawing=true; do not call Database.SaveAs or queue QSAVE from the C# code.

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYesC# code to execute. Has access to Document, CivilDoc, Database, Transaction, Editor. Example: var id = TinSurface.Create(Database, "MySurface"); return new { success = true };
descriptionNoOptional human-readable summary; excluded from operation audit logs.
saveDrawingNoWhen true, save the currently named DWG after the write transaction commits and wait for completion. Use this instead of Database.SaveAs or Document.SendStringToExecute("QSAVE") in code. An unsaved drawing must first be named in Civil 3D.
idempotencyKeyNoOptional opaque session key. Reuse it only to manually reconcile an uncertain outcome; use a new key for an intentional new write.
expectedDrawingYesExpected active drawing identity checked immediately before Civil API access.

TDQS

A4.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does well: it notes the committed transaction, available globals, JSON return, drawing identity check, and save workflow. It does not mention exception handling or failure rollback, but that is a minor gap for a code-execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and front-loaded with the core purpose, then elaborates on key parameters and constraints. It is not overly verbose, though bullet formatting could improve scannability; still, every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex code-execution tool with no output schema, the description explains available globals, return format, drawing identity requirements, save behavior, and sibling distinction. No critical operational detail is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, yet the description adds significant context: expectedDrawing provenance and check timing, saveDrawing conditions (must be named), idempotencyKey purpose, and an example for code. It clearly enhances schema-only information.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a precise purpose: executing C# code with write access in Civil 3D. It explicitly scopes the tool to modifying the drawing ('Use this for operations that MODIFY the drawing'), which distinguishes it from the read-only sibling civil3d_query.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides clear usage criteria: use for modifications, not for reads; requires expectedDrawing from a prior civil3d_query; and warns against calling Database.SaveAs or queuing QSAVE, directing the user to the saveDrawing parameter instead. This fully covers when and how to use it versus alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

civil3d_queryA

Execute C# code in Civil 3D in READ-ONLY mode (no changes saved). Available globals: Document, CivilDoc, Database, Transaction, Editor. All Civil 3D namespaces are auto-imported. Return a value to get results as JSON. Use this for querying data: listing objects, getting properties, analyzing surfaces, etc. Omit expectedDrawing only to bootstrap Database.Filename and Database.FingerprintGuid; otherwise supply it to guard the active drawing.

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYesC# code to query data. Has access to Document, CivilDoc, Database, Transaction, Editor. Example: var surfaces = new List<object>(); foreach (ObjectId id in CivilDoc.GetSurfaceIds()) { var s = Transaction.GetObject(id, OpenMode.ForRead) as TinSurface; surfaces.Add(new { s.Name, s.Layer }); } return surfaces;
expectedDrawingNoExpected active drawing identity checked immediately before Civil API access.

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does substantial work: it discloses read-only semantics ('no changes saved'), available globals (Document, CivilDoc, Database, Transaction, Editor), auto-imported namespaces, the JSON return mechanism, and the expectedDrawing guard vs. bootstrap behavior. It does not cover error behavior for failed compilation or thrown exceptions at runtime, which is a notable gap for a code-execution tool, but the disclosed traits are rich.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, each earning its place: purpose/globals/return semantics, when-to-use, and the expectedDrawing rule. The first sentence is dense but not wasteful; the most critical differentiator (READ-ONLY) is front-loaded before supporting details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex code-execution tool with no annotations and no output schema, the description covers the essentials: execution mode, environment globals, namespaces, return format, and the identity-guard parameter semantics. The main omissions are error/exception behavior and the exact failure mode when expectedDrawing mismatches, which an agent invoking arbitrary C# code would benefit from knowing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds genuine value beyond the schema by explaining when to omit expectedDrawing entirely — 'Omit expectedDrawing only to bootstrap Database.Filename and Database.FingerprintGuid; otherwise supply it to guard the active drawing' — a semantic the schema's field descriptions do not convey.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Execute C# code in Civil 3D in READ-ONLY mode (no changes saved).' It further scopes the tool with 'Use this for querying data: listing objects, getting properties, analyzing surfaces, etc.', which clearly differentiates it from the sibling civil3d_execute. An agent can tell immediately what this tool does and how it differs.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

'Use this for querying data' is an explicit when-to-use statement with concrete examples. The READ-ONLY framing implies that mutations belong to the sibling civil3d_execute, though it never names that alternative or states a when-not-to-use condition explicitly, so it stops short of a full 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

civil3d_skillsA

Browse and read Civil 3D code skills (documented C# code templates). Use 'list' to see available skills, 'search' to find by keyword, 'get' to read the full skill with code template, or 'api_lookup' to search public metadata from already-loaded Civil 3D host assemblies. Skills are pre-built C# patterns you can adapt and execute via civil3d_execute or civil3d_query.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum list/search/api_lookup results to return (integer 1-50; default 20)
queryNoSearch query for 'search' or 'api_lookup' action
actionYeslist = browse skill metadata, search = find by keyword, get = read full skill, api_lookup = read-only public API metadata search
cursorNoOpaque nextCursor from a prior list/search call with the same filters
assemblyNoAllowlisted loaded host assembly filter for api_lookup
categoryNoFilter by category (surfaces, alignments, points, etc.)
namespaceNoNamespace prefix filter for api_lookup
skillNameNoSkill name for 'get' action

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the behavioral disclosure burden. It clearly labels the tool as read-only ('Browse and read', 'read-only public API metadata search'), implying no state changes. It also notes that execution happens via sibling tools, which further clarifies that this tool itself does not modify anything. The absence of side-effect warnings is acceptable given the read-only framing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three concise sentences, each adding critical information: the core purpose, the list of actions, and the relationship to sibling tools. It front-loads the main purpose and avoids redundancy or filler. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only tool with four actions, the description is nearly complete. It explains the actions, implies the output (list of skills, search results, full skill content, API metadata), and points to the execution siblings. While it doesn't detail pagination or output structure, those are typically understood and the schema covers cursor details. The description is sufficient for an agent to call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all eight parameters have descriptions in the schema. The tool description adds contextual meaning (e.g., what 'get' does, that api_lookup is read-only) but does not explain parameter syntax or constraints beyond the schema. This meets the baseline of 3 but does not exceed it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb-resource pair ('Browse and read Civil 3D code skills') and immediately enumerates the four supported actions (list, search, get, api_lookup). It also distinguishes itself from the sibling tools by noting that skills 'can be adapted and execute via civil3d_execute or civil3d_query.' This clearly sets its scope apart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains the tool's role as a browsing/reading layer and explicitly points to the sibling tools for execution. It also differentiates between read actions (list/search/get) and the read-only metadata api_lookup. While it doesn't list explicit 'when not to use' scenarios, the purpose is clear enough for an agent to decide between this and its siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv1.0.0
    • First observedcivil3d_execute
    • First observedcivil3d_query
    • First observedcivil3d_skills

TDQS

A4.4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a clear, non-overlapping purpose: execute for write operations, query for read-only operations, and skills for browsing code templates. The read/write distinction is explicitly stated, so agents should not confuse execute and query.

Naming Consistency4/5

All tools share the civil3d_ prefix and snake_case, but the suffixes mix verbs (execute, query) with a noun (skills), making it not a strictly consistent verb_noun pattern. The naming is still predictable and readable.

Tool Count5/5

Three tools is a well-scoped set for a server that provides arbitrary C# execution capabilities; each tool serves a distinct and necessary function. The count falls within the typical 3-15 range.

Completeness5/5

The combination of execute and query covers the full range of Civil 3D operations (create, edit, delete, query), and skills fills the learning gap. No obvious missing functionality for the stated purpose.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables AI assistants to interact with Autodesk Civil 3D through natural language, supporting tools for surfaces, alignments, profiles, corridors, pipe networks, COGO points, and AutoCAD geometry.
    9
    3
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Lets any MCP-compatible AI assistant read and edit Autodesk Civil 3D drawings through tools for alignments, surfaces, corridors, pipe networks, quantity takeoff, and cut/fill, using a local bridge plugin and named pipes.
    MIT