TwinCAT Knowledge MCP Server

TwinCAT Knowledge MCP Server

Enables semantic search over TwinCAT 3 documentation using natural language queries, with intelligent caching for fast results.

Category
访问服务器

README

TwinCAT Knowledge MCP Server

A Model Context Protocol (MCP) server providing semantic search access to TwinCAT 3 documentation. This project includes tools for converting PDFs to Markdown, generating embeddings, and hosting a searchable API on GitHub Pages.

Overview

This project provides a complete semantic search solution for TwinCAT 3 documentation:

  1. PDF Conversion: Converts 290 TwinCAT 3 documentation PDFs from Beckhoff to Markdown format
  2. Embedding Generation: Generates semantic embeddings using transformer models
  3. Search API: Hosts a search API on GitHub Pages using Transformers.js
  4. MCP Server: Provides an MCP-compatible interface for Cursor and LM Studio

Architecture

[Generate Embeddings] → Push to GitHub
            ↓
[GitHub Pages] → Transformers.js API
            ↓
[Local MCP Server] → Returns to Cursor/LM Studio

Features

  • Semantic Search: Natural language search using transformer-based embeddings
  • Persistent Cache: Intelligent caching system for 90% faster subsequent searches
  • GitHub Pages API: Free, unlimited hosting with Transformers.js
  • Rich Metadata: Structured YAML frontmatter for advanced filtering
  • Category Support: Search by product, category, version, and more
  • No GPU Required: The MCP server runs on CPU, works on any machine

Quick Start

Local Installation

  1. Clone the repository:
git clone https://github.com/njfsmallet-eng/twincat-knowledge-mcp-server.git
cd twincat-knowledge-mcp-server
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

This compiles TypeScript to JavaScript in the dist/ directory. The dist/ folder is not tracked in git, so you need to build after cloning.

Note: You only need to rebuild if you modify the source code. The compiled dist/ files are not committed to git.

  1. Add to your Cursor/LM Studio mcp.json:

Option A: Using compiled CommonJS (Recommended)

{
  "mcpServers": {
    "twincat-knowledge": {
      "command": "node",
      "args": ["C:\\Users\\YourUsername\\path\\to\\twincat-knowledge-mcp-server\\dist\\index.js"],
      "env": {}
    }
  }
}

Option B: Using TypeScript directly

{
  "mcpServers": {
    "twincat-knowledge": {
      "command": "npx",
      "args": ["-y", "tsx", "C:\\Users\\YourUsername\\path\\to\\twincat-knowledge-mcp-server\\src\\index.ts"],
      "env": {}
    }
  }
}

Note: Replace the path with your actual repository location. Use double backslashes (\\) for Windows paths.

Configuration for Different Platforms

The configuration works identically across all compatible platforms:

  • Cursor: Uses the mcp.json file in your user directory (typically C:\Users\YourUsername\.cursor\mcp.json on Windows)
  • LM Studio: Uses the same MCP server configuration format

Both platforms support the standard MCP stdio protocol used by this server.

Usage

Using the MCP Server

Once configured in Cursor or LM Studio, use the search_knowledge tool:

"Describe what TwinCAT Scope is and its main features."

Available filters:

  • category: Communication, PLC, Motion_Control, etc.
  • product: TF6100, TC3, TE1000, etc.
  • top_k: Number of results (default: 5)

Cache System

The MCP server includes an intelligent caching system that dramatically improves performance:

  • First call: Downloads and caches all data (~16 seconds)
  • Subsequent calls: Loads from cache (~1.6 seconds)
  • Performance improvement: 90% faster after initial cache population
  • Cache location: .cache/ directory in project root
  • Persistent: Cache survives between MCP server sessions
  • Automatic: No manual configuration required

Cache contents:

  • Xenova embedding model (~50 MB)
  • Documentation chunks (42,314 chunks)
  • Pre-computed embeddings (~57 MB compressed)

Testing the Search API

You can test the search functionality directly in your browser at: https://njfsmallet-eng.github.io/twincat-knowledge-mcp-server/

This web interface allows you to:

  • Test semantic search queries
  • See real-time results from the TwinCAT documentation
  • Verify that the API is working correctly before configuring Cursor or LM Studio

File Structure

twincat-knowledge-mcp-server/
├── src/                         # TypeScript source
│   ├── index.ts                # MCP server
│   ├── types.ts                # Type definitions
│   ├── github-pages-client.ts  # API client
│   └── cache-manager.ts        # Cache management
├── dist/                        # Compiled JavaScript (CommonJS)
│   ├── index.js                # Compiled MCP server
│   └── *.js                     # Other compiled files
├── scripts/                     # Python scripts
│   ├── chunking.py             # Text chunking
│   ├── generate_embeddings.py  # Embedding generation
│   └── README.md               # Scripts documentation
├── gh-pages/                    # GitHub Pages files
│   ├── index.html              # API interface
│   └── search.js               # Transformers.js search
├── embeddings/                  # Generated embeddings
│   ├── chunks.json             # Chunks with metadata
│   ├── embeddings.npy.gz       # Compressed vectors
│   └── metadata.json           # Generation stats
├── docs/                        # Converted markdown docs
├── .cache/                      # Persistent cache (auto-created)
│   ├── chunks.json             # Cached documentation chunks
│   ├── embeddings.npy.gz       # Cached embeddings
│   └── model/                  # Xenova model cache
│       └── Xenova/
│           └── all-MiniLM-L6-v2/
├── .github/workflows/           # CI/CD
│   └── deploy-pages.yml        # GitHub Pages deployment
├── package.json                 # Node.js config
├── tsconfig.json               # TypeScript config
└── requirements.txt            # Python dependencies

Dependencies

Python (for embedding generation only):

  • sentence-transformers - Transformer models for embeddings
  • torch - PyTorch
  • numpy - Numerical operations
  • pyyaml - YAML parsing
  • tqdm - Progress bars

Note: Python dependencies are only needed to generate embeddings. The MCP server itself requires only Node.js.

Node.js:

  • @modelcontextprotocol/sdk - MCP protocol
  • @xenova/transformers - Transformers.js for embeddings
  • typescript - TypeScript compiler (for building)

The project compiles TypeScript to CommonJS for optimal Node.js compatibility.

Architecture Details

Embedding Generation

  • Model: sentence-transformers/all-MiniLM-L6-v2 (384 dimensions)
  • Format: Float32 NumPy arrays compressed with gzip
  • Size: ~57 MB compressed for all documents
  • Note: Embeddings are pre-generated and hosted on GitHub Pages. The MCP server does not require any GPU or Python dependencies to run.

Search API

  • Frontend: Transformers.js in browser
  • Model: Xenova/all-MiniLM-L6-v2 ONNX (quantized)
  • Latency: ~500ms-1s per query
  • Cache: IndexedDB for model caching

MCP Server

  • Transport: stdio
  • Compatibility: Cursor, LM Studio (tested)
  • Module System: CommonJS (compiled from TypeScript)
  • Language: TypeScript source, compiled to JavaScript
  • Local Installation: Clone and configure directly
  • Cache System: Persistent disk-based caching for optimal performance
  • Performance: 90% faster after initial cache population

Local Usage

Requirements

  • Node.js: >=18.0.0
  • TypeScript: >=5.9.0 (for building)
  • Dependencies: Only MCP SDK and Transformers.js required
  • Size: ~160 MB (includes embeddings and documentation)
  • Cache: Additional ~110 MB for persistent cache (auto-created)
  • Build: Run npx tsc to compile TypeScript to CommonJS in dist/ directory
  • Files: 338 files total

License

MIT License

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选