StarUML控制器MCP核心库

提供共享基础设施和常用工具定义,用于快速构建和运行各类UML图的StarUML控制器MCP服务器。

  • by pontasan
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 pontasan/staruml-controller-mcp-core

使用说明

staruml-controller-mcp-core

Shared core package for all StarUML Controller MCP servers. Provides the infrastructure layer — HTTP client, tool registry, response formatter, server factory — and common tool definitions shared across every diagram-specific MCP server.

What This Package Does

Each diagram-specific MCP server (e.g., staruml-controller-erd-mcp, staruml-controller-seq-mcp) depends on this package. It provides:

  1. Common tools — General, Project, Utility, Diagrams, Notes, Shapes, Views, Elements
  2. Family configs — Declarative definitions for 25 diagram families (ERD, Sequence, Class, etc.)
  3. Server factory — One-call createServer() to spin up a complete MCP server with common + family tools
  4. Tool registry — Metadata-driven engine that registers tools on McpServer, handling host/port injection, URL parameter encoding, query strings, and request body building
  5. HTTP client — REST client with timeout, connection error handling, and automatic ID encoding
  6. Response formatter — Consistent MCP response formatting with error detection

Architecture

src/
  index.ts                  # Public API exports
  server-factory.ts         # createServer(name, version, familyTools) → McpServer
  stdio-runner.ts           # runStdioServer(name, version, familyTools) — serve over stdio
  tool-registry.ts          # registerAll(server, tools) — declarative tool registration
  config.ts                 # STARUML_PASSWORD / STARUML_HOST / STARUML_PORT
  http-client.ts            # request(method, host, port, path, body) — REST client (sends the password)
  file-transfer.ts          # write / read files on the machine running the MCP server
  response-formatter.ts     # format(response), formatError(name, error)
  tools/
    general.ts              # get_status, get_element, tags, save/open project
    project.ts              # project_new, project_close, import, export
    utility.ts              # undo, redo, search, validate, mermaid_import, generate_diagram
    diagrams.ts             # diagram CRUD, export, layout, zoom, create_view_of
    notes.ts                # notes, note links, free lines
    shapes.ts               # shape CRUD (Text, Rect, Ellipse, Image, etc.)
    views.ts                # view position/style, reconnect, align
    elements.ts             # element update/delete, children, relocate, reorder
    family-factory.ts       # generateFamilyTools(config) — declarative tool generator
    families/
      types.ts              # FamilyConfig, ResourceConfig, RelationConfig, etc.
      erd.ts                # ERD family (data models, entities, columns, relationships, DDL)
      seq.ts                # Sequence family (interactions, lifelines, messages, fragments)
      class.ts              # Class/Package family
      usecase.ts            # Use Case family
      activity.ts           # Activity family
      statemachine.ts       # State Machine family
      component.ts          # Component family
      deployment.ts         # Deployment family
      object.ts             # Object family
      communication.ts      # Communication family
      composite.ts          # Composite Structure family
      infoflow.ts           # Information Flow family
      profile.ts            # Profile family
      timing.ts             # Timing family
      overview.ts           # Interaction Overview family
      flowchart.ts          # Flowchart family
      dfd.ts                # DFD family
      bpmn.ts               # BPMN family
      c4.ts                 # C4 family
      sysml.ts              # SysML family
      wireframe.ts          # Wireframe family
      mindmap.ts            # MindMap family
      aws.ts                # AWS family
      azure.ts              # Azure family
      gcp.ts                # GCP family

Usage

Creating a Diagram-Specific MCP Server

A diagram-specific MCP server is a single call:

#!/usr/bin/env node
import { runStdioServer, erdTools } from "staruml-controller-mcp-core"

runStdioServer(
  "staruml-controller-erd",
  "2.0.0",
  erdTools       // diagram-specific tools
)

runStdioServer() serves the MCP specification 2026-07-28 over stdio and also answers clients that still use the earlier initialize handshake. The MCP SDK is a dependency of this package only, so diagram-specific servers do not depend on it.

runStdioServer() builds the server with createServer(), which automatically includes all common tools (General, Project, Utility, Diagrams, Notes, Shapes, Views, Elements) and merges them with the provided family tools.

Using the Family Factory

For custom diagram families, define a FamilyConfig and generate tools:

import { generateFamilyTools, type FamilyConfig } from "staruml-controller-mcp-core"

const config: FamilyConfig = {
  prefix: "mydiagram",
  label: "My Diagram",
  diagrams: { types: ["MyDiagramType"] },
  resources: [
    { name: "nodes", types: ["MyNode"], createFields: ["name", "label"] }
  ],
  relations: [
    { name: "edges", type: "MyEdge" }
  ],
}

const tools = generateFamilyTools(config)

Using Individual Exports

All modules are individually exported for fine-grained control:

// Infrastructure
import { request, encodeId } from "staruml-controller-mcp-core"
import { format, formatError } from "staruml-controller-mcp-core"
import { registerAll, type ToolDefinition } from "staruml-controller-mcp-core"

// Common tool arrays
import { generalTools, diagramTools, noteTools } from "staruml-controller-mcp-core"

// Family configs
import { erdTools, seqTools, classTools } from "staruml-controller-mcp-core"

// Type definitions
import type { FamilyConfig, ResourceConfig, RelationConfig } from "staruml-controller-mcp-core"

Build

npm install
npm run build

Outputs to dist/ with TypeScript declarations (.d.ts).

Prerequisites

  • Node.js 20+

Configuration

The MCP servers read their connection settings from environment variables:

Variable Required Description
STARUML_PASSWORD Yes The password entered when the StarUML Controller server was started
STARUML_HOST No Host of the machine running StarUML (default: localhost)
STARUML_PORT No Port of the StarUML Controller server (default: 12345)

The password is never a tool parameter, so it does not pass through the AI conversation. An invalid STARUML_PORT stops the server at startup; a missing STARUML_PASSWORD is reported by the first tool call.

File Transfer

The StarUML Controller never writes to a path given by a client. Tools with fileTransfer in their definition move file contents through the HTTP response or request, and this package reads or writes the file on the machine running the MCP server:

fileTransfer.kind Tools Behavior
download diagram_export, project_export, erd_generate_ddl The response carries one file; it is written to path
downloadDir project_export_all, project_export_doc The response carries several files; they are written under the directory path
upload project_import The file at path is read and sent in the request

File contents are not returned to the AI. The tool result reports only the saved path and size. save_project and open_project are different: their path is on the machine running StarUML.

Tests

# tools/list over stdio, with the 2026-07-28 protocol or the earlier handshake
node test/list-tools.mjs ../staruml-controller-erd-mcp/dist/index.js modern
node test/list-tools.mjs ../staruml-controller-erd-mcp/dist/index.js legacy

# End-to-end through the MCP layer (StarUML must be running with the controller server started)
STARUML_PASSWORD=<password> node test/smoke-erd.mjs ../staruml-controller-erd-mcp/dist/index.js modern

# Any diagram-specific server: get_status, all list tools, diagram create/get/update/delete
STARUML_PASSWORD=<password> node test/smoke-family.mjs ../staruml-controller-class-mcp/dist/index.js modern

Diagram Servers Using This Package

Server Family Config
staruml-controller-erd-mcp erdTools
staruml-controller-seq-mcp seqTools
staruml-controller-class-mcp classTools
staruml-controller-usecase-mcp usecaseTools
staruml-controller-activity-mcp activityTools
staruml-controller-statemachine-mcp statemachineTools
staruml-controller-component-mcp componentTools
staruml-controller-deployment-mcp deploymentTools
staruml-controller-object-mcp objectTools
staruml-controller-communication-mcp communicationTools
staruml-controller-composite-mcp compositeTools
staruml-controller-infoflow-mcp infoflowTools
staruml-controller-profile-mcp profileTools
staruml-controller-timing-mcp timingTools
staruml-controller-overview-mcp overviewTools
staruml-controller-flowchart-mcp flowchartTools
staruml-controller-dfd-mcp dfdTools
staruml-controller-bpmn-mcp bpmnTools
staruml-controller-c4-mcp c4Tools
staruml-controller-sysml-mcp sysmlTools
staruml-controller-wireframe-mcp wireframeTools
staruml-controller-mindmap-mcp mindmapTools
staruml-controller-aws-mcp awsTools
staruml-controller-azure-mcp azureTools
staruml-controller-gcp-mcp gcpTools

License

MIT