关于 Tianji Thinking Models
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
19收录的工具列表 · 更新于 3 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| lang | enum | 否 | 语言代码('zh' 或 'en'),默认为 'zh'zh | en |
| category | string | 否 | 主分类名称(可选) |
| subcategory | string | 否 | 子分类名称(可选,需同时提供主分类) |
| limit | number | 否 | 返回结果数量限制,默认为100 |
详细介绍
“Tianji” — 思维模型 MCP 服务

智能思维工具箱:将系统化思维方法融入问题解决过程
目录
什么是 “Tianji”?
“Tianji” 是一个功能强大的思维模型 MCP 服务,整合了数百种思维模型、框架和方法论,帮助用户以更系统、更全面的方式思考问题。通过 MCP(Model Context Protocol)接口,AI 助手可以使用这些思维工具,并在对话中无缝运用结构化思维方法。“Tianji” 这个名字源于中国古语“天机不可泄露”,寓意它能帮助用户发掘更深层的思维模式与智慧。
核心功能
- 丰富的思维模型库:涵盖决策理论、系统思维和概率思维等多个领域的经典思维模型
- 智能模型推荐:根据问题特征自动推荐最合适的思维模型
- 交互式推理过程:引导用户进行结构化思考,逐步分析问题
- 学习与适应系统:通过用户反馈持续改进推荐算法
- 模型创建与组合:允许创建新模型或组合现有模型,生成创新的思维框架
工具概览
探索工具
- list-models:列出所有思维模型或按类别筛选
- search-models:按关键词搜索思维模型
- get-categories:获取所有思维模型类别
- get-model-info:获取某个思维模型的详细信息
- get-related-models:获取与特定模型相关的其他模型
问题解决工具
- recommend-models-for-problem:根据问题关键词推荐合适的思维模型
- interactive-reasoning:交互式推理过程指导
- generate-validate-hypotheses:针对问题生成多个假设,并提供验证方法
- explain-reasoning-process:解释模型的推理过程和所采用的思维模式
创建工具
- create-thinking-model:创建新的思维模型
- update-thinking-model:更新现有思维模型的任意字段,包括基本信息和可视化数据,无需重新创建整个模型
- emergent-model-design:通过组合现有模型创建新的思维模型
- delete-thinking-model:删除不需要的思维模型
系统与学习工具
- get-started-guide:新手指南
- get-server-version:获取服务版本信息
- count-models:统计当前思维模型总数
- record-user-feedback:记录用户对思维模型使用体验的反馈
- detect-knowledge-gap:检测用户查询中的知识缺口
- get-model-usage-stats:获取思维模型的使用统计信息
- analyze-learning-system:分析思维模型学习系统的状态
工具函数参数和返回值
以下是所有工具函数的详细参数和返回值:
探索工具
list-models
列出所有思维模型,或按类别筛选。
参数:
lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]category(可选):主类别名称subcategory(可选):子类别名称(需提供主类别)limit(可选,默认值为 100):返回结果数量上限
返回值:
{
"models": [
{
"id": "modelID",
"name": "model name",
"definition": "model definition",
"category": "model category"
}
// ... more models
],
"total": total number of models queried,
"filter": "applied filter conditions"
}
search-models
按关键词搜索思维模型。
参数:
query(必填):搜索关键词lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]limit(可选,默认值为 10):返回结果数量上限
返回值:
{
"results": [
{
"id": "modelID",
"name": "model name",
"definition": "model definition",
"purpose": "model purpose",
"match_score": match score,
"match_reasons": ["match reason 1", "match reason 2"]
}
// ... more matching results
],
"total": total number of matching models,
"query": "search keywords"
}
get-categories
获取所有思维模型类别。
参数:
lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"categories": [
{
"name": "category name",
"count": number of models in this category,
"subcategories": [
{
"name": "subcategory name",
"count": number of models in this subcategory
}
// ... more subcategories
]
}
// ... more categories
],
"total_categories": total number of categories,
"total_models": total number of all models
}
get-model-info
获取思维模型的详细信息。
参数:
model_id(必填):思维模型的唯一 IDfields(可选,默认值为 ["basic"]):要返回的字段,可选项:["all", "basic", "detail", "teaching", "warnings", "visualizations"]lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"id": "modelID",
"name": "model name",
"definition": "model definition",
"purpose": "model purpose",
// Different levels of detailed information based on the fields parameter
"category": "model category",
"subcategories": ["subcategory 1", "subcategory 2"],
"application_steps": ["application step 1", "application step 2"],
"popular_science_teaching": [
{
"concept_name": "concept name",
"explanation": "popular explanation"
}
],
"limitations": [
{
"limitation_name": "limitation name",
"description": "limitation description"
}
],
"common_pitfalls": [
{
"pitfall_name": "common pitfall name",
"description": "pitfall description"
}
],
// Visualization-related fields (if requested)
"visualizations": {
"flowcharts": [...],
"tables": [...],
"bar_charts": [...],
"lists": [...]
}
}
get-related-models
获取与指定模型相关的模型。
参数:
model_id(必填):思维模型的唯一 IDlang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]limit(可选,默认值为 5):返回结果数量上限use_enhanced_similarity(可选,默认值为 true):是否使用增强相似度评估
返回值:
{
"related_models": [
{
"id": "related model ID",
"name": "related model name",
"similarity_score": similarity score,
"relationship_type": "relationship type",
"definition": "model definition"
}
// ... more related models
],
"source_model": {
"id": "source model ID",
"name": "source model name"
}
}
问题解决工具
recommend-models-for-problem
根据问题关键词推荐合适的思维模型。
参数:
problem_keywords(必填):问题关键词数组problem_context(可选):问题的完整背景描述lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]limit(可选,默认值为 10):返回结果数量上限use_learning_adjustment(可选,默认值为 true):是否使用学习系统调整推荐结果
返回值:
{
"models": [
{
"id": "model ID",
"name": "model name",
"match_score": match score,
"match_reasons": ["match reason 1", "match reason 2"],
"definition": "model definition",
"purpose": "model purpose",
"adjustment_reason": "adjustment reason (if learning adjustment is used)"
}
// ... more recommended models
],
"learning_adjusted": whether learning adjustment was applied,
"total_models_matched": total number of matching models
}
interactive-reasoning
提供交互式推理过程指导。
参数:
initialContext(必填):初始问题或情况描述reasoningStage(必填):当前推理阶段,可选项:["information_gathering", "hypothesis_generation", "hypothesis_testing", "conclusion"]currentPathId(可选):当前推理路径 ID(如果处于已有推理过程中)requiredInformation(可选):所需补充信息的数组lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"pathId": "reasoning path ID",
"currentStage": "current stage",
"suggestedActions": [
"suggested action 1",
"suggested action 2"
],
"relevantModels": [
{
"id": "related model ID",
"name": "related model name",
"relevance_reason": "relevance reason"
}
// ... more related models
],
"nextStep": {
"action": "next action",
"description": "next step description"
// May contain other stage-specific data
}
}
generate-validate-hypotheses
针对问题生成多个假设,并提供验证方法。
参数:
problem(必填):待解决的问题context(必填):与问题相关的背景信息lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"problem_statement": "problem statement",
"hypotheses": [
{
"hypothesis": "hypothesis content",
"rationale": "formation rationale",
"validation_methods": [
{
"method": "validation method",
"expected_outcome": "expected result",
"resources_needed": "resources needed"
}
// ... more validation methods
],
"potential_biases": ["potential bias 1", "potential bias 2"]
}
// ... more hypotheses
],
"applicable_thinking_models": [
{
"id": "applicable model ID",
"name": "applicable model name",
"relevance": "relevance description"
}
// ... more applicable models
]
}
explain-reasoning-process
解释模型的推理过程和应用的思维模式。
参数:
problemDescription(必填):问题或情况描述reasoningSteps(必填):推理步骤详情数组,每个步骤包含:description(必填):推理步骤描述modelIds(可选):所用思维模型 ID 的数组evidence(可选):支持证据的数组confidence(可选,默认值为 0.8):置信度(0-1)
conclusion(必填):推理结论lang(必填,默认值为 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"reasoning_path": {
"problem": "problem description",
"steps": [
{
"description": "step description",
"models_applied": [
{
"id": "applied model ID",
"name": "applied model name",
"explanation": "model application explanation"
}
],
"cognitive_biases_avoided": ["avoided cognitive bias 1", "avoided cognitive bias 2"],
"confidence": confidence value
}
// ... more reasoning steps
],
"conclusion": "conclusion",
"meta_cognition_insights": ["meta-cognition insight 1", "meta-cognition insight 2"]
},
"visualization": "reasoning path visualization (e.g., flowchart)"
}
创建工具
create-thinking-model
创建新的思维模型。
参数:
id(必填):模型的唯一标识符name(必填):模型名称definition(必填):模型的简明定义purpose(必填):模型的主要用途和使用场景category(必填):模型的主要类别lang(必填,默认值为 "zh"):模型语言,可选项:["zh", "en"]subcategories(可选):模型的子类别列表tags(可选):相关标签author(可选):模型作者source(可选):模型来源prompt(可选):详细的提示词/角色扮演指南example(可选):模型用法的简短示例use_cases(可选):模型的使用场景interaction(可选):使用此模型与用户交互的指南constraints(可选):使用此模型的限制条件popular_science_teaching(可选):模型的科普教学内容limitations(可选):模型的局限性common_pitfalls(可选):使用模型时常见的陷阱common_problems_solved(可选):模型解决的常见问题- 各类可视化数据(可选):流程图、表格、条形图、列表等
返回值:
{
"status": "operation status",
"message": "operation message",
"model_id": "created model ID"
}
update-thinking-model
更新现有思维模型的任意字段。
参数:
model_id(必填):要更新的模型 ID- 要更新的其他字段(可选):与 create-thinking-model 参数相同
返回值:
{
"status": "operation status",
"message": "operation message",
"updated_fields": ["updated field 1", "updated field 2"]
}
emergent-model-design
通过组合现有思维模型创建新的思维模型。
参数:
source_model_ids(必填):用于组合的源模型 ID 列表,最少 2 个,最多 10 个target_model_id(必填):新模型的唯一标识符target_model_name(必填):新模型名称design_goal(必填):设计目标和用途描述connection_description(可选):源模型组合方式的描述category(可选):新模型的主要类别lang(必填,默认值为 "zh"):模型语言,可选项:["zh", "en"]
返回值:
{
"status": "operation status",
"message": "operation message",
"model_id": "created model ID",
"emergent_properties": ["emergent property 1", "emergent property 2"],
"source_models_used": [
{
"id": "source model ID",
"name": "source model name",
"contribution": "contribution to the new model"
}
// ... more source models
]
}
delete-thinking-model
删除不需要的思维模型。
参数:
model_id(必需):要删除的模型 IDlang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]confirm(必需):确认删除,必须为 true
返回值:
{
"status": "operation status",
"message": "operation message",
"deleted_model_id": "deleted model ID"
}
系统与学习工具
get-started-guide
获取入门指南。
参数:
user_objective(可选,默认值 "explore"):用户目标,可选项:["explore", "solve_problem", "create_model", "learn_tools"]expertise_level(可选,默认值 "beginner"):用户经验水平,可选项:["beginner", "intermediate", "advanced"]lang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"welcome_message": "welcome message",
"system_overview": "system overview",
"suggested_first_steps": [
{
"step": "step description",
"tool": "recommended tool",
"example": "usage example"
}
// ... more steps
],
"recommended_models": [
{
"id": "recommended model ID",
"name": "recommended model name",
"purpose": "model purpose"
}
// ... more recommended models
],
"learning_path": "learning path suggestions",
"additional_resources": ["additional resource 1", "additional resource 2"]
}
get-server-version
获取服务版本和状态信息。
参数:
- 无
返回值:
{
"version": "version number",
"build_date": "build date",
"api_version": "API version",
"status": "server status",
"uptime": uptime in seconds,
"models_loaded": total number of models loaded
}
count-models
统计当前思维模型总数。
参数:
lang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"total_count": total number of models,
"language": "language code",
"category_counts": {
"category1": number of models in this category,
"category2": number of models in this category
// ... more category statistics
}
}
record-user-feedback
记录用户对思维模型使用体验的反馈。
参数:
modelIds(必需):相关思维模型的 ID 数组context(必需):应用模型时的背景或问题描述feedbackType(必需):反馈类型,可选项:["helpful", "not_helpful", "incorrect", "insightful", "confusing"]comment(可选):详细反馈说明或评论applicationResult(可选):模型应用结果描述suggestedImprovements(可选):建议改进项数组lang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"status": "operation status",
"message": "operation message",
"insights": "insights gained from the feedback"
}
detect-knowledge-gap
检测用户查询中的知识缺口。
参数:
query(必需):用户查询或问题matchThreshold(可选,默认值 0.5):匹配阈值,低于此值将被视为知识缺口lang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"knowledge_gaps": [
{
"concept": "missing concept",
"match_score": match score,
"suggested_models": [
{
"id": "suggested model ID",
"name": "suggested model name",
"relevance": "relevance description"
}
// ... more suggested models
],
"learning_resources": ["learning resource 1", "learning resource 2"]
}
// ... more knowledge gaps
],
"query_coverage": query coverage,
"recommendations": ["recommendation 1", "recommendation 2"]
}
get-model-usage-stats
获取思维模型的使用统计信息。
参数:
modelId(必需):思维模型的唯一 IDlang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"model_id": "model ID",
"model_name": "model name",
"usage_count": usage count,
"average_rating": average rating,
"feedback_distribution": {
"helpful": number of helpful feedback,
"not_helpful": number of unhelpful feedback,
"incorrect": number of incorrect feedback,
"insightful": number of insightful feedback,
"confusing": number of confusing feedback
},
"common_usage_contexts": ["common usage context 1", "common usage context 2"],
"trend": "usage trend description",
"related_models_also_used": [
{
"id": "related model ID",
"name": "related model name",
"co_occurrence_count": co-occurrence count
}
// ... more related models
]
}
analyze-learning-system
分析思维模型学习系统的状态。
参数:
lang(必需,默认值 "zh"):语言代码,可选项:["zh", "en"]
返回值:
{
"system_health": {
"total_feedback_count": total feedback count,
"knowledge_coverage": knowledge coverage,
"adaptation_score": adaptation score
},
"top_performing_models": [
{
"id": "model ID",
"name": "model name",
"effectiveness_score": effectiveness score
}
// ... more well-performing models
],
"identified_gaps": ["identified gap 1", "identified gap 2"],
"learning_trends": ["learning trend 1", "learning trend 2"],
"improvement_suggestions": ["improvement suggestion 1", "improvement suggestion 2"]
}
使用场景
解决复杂问题
面对复杂问题时,系统可以推荐多个思维模型,帮助你从不同角度分析问题,避免思维盲点。
提升思维质量
通过结构化的思维过程,避免常见的认知偏差,做出更理性的决策。
学习思维模型
系统不仅提供思维模型的定义,还包含详细的教学内容、应用示例和注释,帮助你掌握各种思维工具。
创建自定义模型
当现有模型无法满足需求时,你可以创建新的思维模型,或组合现有模型,构建创新的思维框架。
快速开始
安装(本地开发)
如果你想在本地运行和开发此项目:
git clone https://github.com/yourusername/thinking-models-mcp.git # Replace with your repository address
cd thinking_models_mcp
npm install
npm run build
启动服务(本地开发)
- 正常启动(stdio 模式)
在项目根目录中运行:
或使用 npm 脚本(如果已在 package.json 中配置):node build/thinking_models_server.jsnpm run start
配置指南
你可以将思维模型 MCP 服务集成到任何支持 MCP 协议的客户端。以下是两种不同的实现方式:
方法 1:使用本地 Node.js 运行「Tianji」服务
此方法需要在本地安装和配置「Tianji」服务代码,适用于需要自定义开发或修改服务代码的场景。
{
"mcpServers": {
"tianji": { // "Tianji" server name
"command": "node",
"args": [
"e:\\thinking_models_mcp\\build\\thinking_models_server.js" // Replace with your actual path
]
}
}
// ... other configurations ...
}
方法 2:使用 NPX 从远程 npm 包启动服务
此方法更简单,无需在本地安装完整代码,可直接从 npm 仓库拉取并运行包。
{
"mcpServers": {
"thinking-models": {
"command": "npx",
"args": [
"--no-cache", // Avoid using cached versions, ensure using the latest version
"@thinking-models/mcp-server" // npm package name
// If you need to specify version: "@thinking-models/mcp-server@latest"
]
}
}
// ... other configurations ...
}
命令行参数说明:
node:直接使用本地 Node.js 运行 JavaScript 文件npx:npm 包运行器,无需全局或本地安装即可执行 npm 包中的命令--no-cache:禁用缓存,确保每次都获取最新版本的包,避免使用过时版本
重要提示:服务数据会自动保存在安装目录的
data文件夹中。即使服务重启,之前的数据也会保留,无需额外配置。建议使用--no-cache参数,确保每次都获取最新版本,避免因缓存问题而使用过时功能。
基本用法
「Tianji」服务启动后,你可以通过 MCP 客户端发送请求,访问思维模型工具。例如:
1. What is the current version number of "Tianji"?
2. How many thinking models does "Tianji" currently have available for me to use?
3. I want to check what types of thinking models are in "Tianji", tell me how many categories there are in total?
4. I encountered XXXX event, but I don't know what to do, please have "Tianji" recommend some thinking models that can help me solve the problem.
如果配置正确,客户端应能够调用服务并返回结果。
开发者文档
本节面向希望了解、自定义或扩展思维模型 MCP 服务的开发者。
开发环境设置
环境要求
- Node.js >= 18.0.0
- npm >= 8.0.0(或 yarn、pnpm 等兼容的包管理器)
- TypeScript 5.x
安装依赖(本地开发)
# Assuming you've already cloned the repository and entered the project directory
npm install
开发模式(本地开发)
# Watch mode, automatically recompile TypeScript files when changed
npm run watch
# In another terminal, start the development server (usually runs compiled files from the build directory)
# You might need a tool like nodemon to automatically restart the server
npm run start:dev # (assuming you've configured this script in package.json)
代码架构
文件结构(示例)
thinking_models_mcp/
├── build/ # Compiled JavaScript files
├── src/ # TypeScript source code
│ ├── thinking_models_server.ts # Main server logic and tool registration
│ ├── types.ts # TypeScript type definitions
│ ├── utils.ts # Common utility functions
│ ├── similarity_engine.ts # Similarity calculation logic
│ ├── reasoning_process.ts # Reasoning process management
│ ├── learning_capability.ts # Learning system functionality
│ ├── recommendations.ts # Model recommendation logic
│ └── response_types.ts # API response type definitions
├── thinking_models_db/ # Thinking model database
│ ├── zh/ # Chinese models (JSON files)
│ └── en/ # English models (JSON files)
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript compiler configuration
└── README.md # This document
核心模块
-
服务核心(thinking_models_server.ts)
- 初始化 MCP 服务实例(来自
@modelcontextprotocol/sdk的McpServer) - 注册所有可用工具,定义其参数架构(使用
zod)和处理函数 - 加载并管理思维模型数据
- 处理客户端请求,并将其路由至相应工具
- 初始化 MCP 服务实例(来自
-
思维模型类型(
types.ts)- 定义核心
ThinkingModel接口,描述模型的数据结构 - 其他与模型相关的 TypeScript 类型和接口
- 定义核心
-
相似度计算引擎(
similarity_engine.ts)calculateQueryMatch:计算用户查询与思维模型之间的匹配度calculateKeywordRelevance:计算关键词列表与思维模型之间的相关性
-
推理流程管理(
reasoning_process.ts)- 用于构建、管理和可视化结构化推理路径
-
学习系统(
learning_capability.ts)recordUserFeedback:记录用户对模型使用情况的反馈detectKnowledgeGap:根据用户查询和反馈检测知识缺口adjustModelRecommendations:根据学习数据调整模型推荐
API 文档
服务 API
服务通信模式:
- stdio API
- 通过标准输入/输出与客户端通信。
- 遵循 MCP 协议规范。
- 通常由客户端(如 Cursor、Claude Desktop)自动管理。
工具 API
每个工具都通过 server.tool() 方法注册,其中包含:
- 工具名称(字符串):客户端调用时使用的名称。
- 工具描述(字符串):对工具功能的简要说明。
- 参数架构(Zod 对象):使用
zod库定义工具接受的参数及其类型、描述和约束。 - 处理函数(异步函数):接收经过验证的参数对象,执行工具逻辑,并返回符合 MCP 协议的响应。
工具注册示例
// filepath: src/thinking_models_server.ts
// ... imports ...
server.tool(
"get-model-count-by-category", // Tool name
"Get the number of thinking models in a specified category", // Tool description
{ // Parameter schema (Zod schema)
category: z.string().describe("Main category of thinking models to query"),
lang: z.enum(["zh", "en"] as const).default("zh").describe("Language code ('zh' or 'en')")
},
async ({ category, lang }) => { // Handler function
try {
const modelsInBuffer = MODELS[lang] || []; // MODELS is a cache of loaded models
const count = modelsInBuffer.filter(m => m.category === category).length;
log(`Tool 'get-model-count-by-category' called: category=${category}, lang=${lang}, count=${count}`);
return {
content: [{
type: "text",
text: JSON.stringify({ category, lang, count }, null, 2)
}]
};
} catch (error: any) {
log(`Tool 'get-model-count-by-category' execution error: ${error.message}`);
return {
content: [{
type: "text",
text: JSON.stringify({ error: "Failed to get model count", message: error.message }, null, 2)
}]
};
}
}
);
扩展指南
添加新工具
- 在 thinking_models_server.ts(或相关模块文件)中,按照上面的示例,使用
server.tool()方法注册新工具。 - 定义清晰的参数架构和描述。
- 实现工具的处理函数,确保其中包含错误处理和日志记录。
- 重新编译项目(
npm run build)。
创建新的思维模型
- 在 zh(中文)或 en(英文)目录中创建一个新的
.json文件。 - 文件名通常是模型的 ID(例如,
new_decision_matrix.json)。 - 文件内容应符合
ThinkingModel接口(定义于 types.ts)的结构。例如:{ "id": "new_decision_matrix", "name": "New Decision Matrix Model", "definition": "A structured method for evaluating options under multiple criteria.", "purpose": "Help make rational choices among complex options.", "category": "Decision Making", "subcategories": ["Multi-criteria Decision"], "tags": ["decision", "matrix", "evaluation", "selection"], "use_cases": ["Product feature prioritization", "Vendor selection"], // ... other fields like popular_science_teaching, limitations, common_pitfalls, visualizations, etc. } - 服务器启动时会自动加载新模型;如果启用了文件监控,则保存文件时也会重新加载。
修改推荐算法
推荐逻辑主要位于 similarity_engine.ts 和 recommendations.ts。
similarity_engine.ts:包含用于计算文本相似度和关键词相关性的核心算法。你可以调整这些算法的权重和所用技术(例如 TF-IDF、嵌入向量等),以提高匹配精度。recommendations.ts:包含getModelRecommendations等函数,它们使用相似度引擎的结果生成最终的模型推荐列表。你可以在此修改逻辑,例如如何合并不同来源的分数,或如何根据上下文调整推荐结果。
测试
项目通常使用 Jest 等测试框架。
编写测试
在 tests 目录中为模块或函数创建测试文件(例如,tests/my_tool.test.ts)。
// tests/example_tool.test.ts
import { server, loadModels } from '../src/thinking_models_server'; // Assuming the server instance is exported
import { ThinkingModel } from '../src/types';
// Mock MCP client request
async function callTool(toolName: string, params: any) {
const toolDefinition = server.capabilities.tools[toolName];
if (!toolDefinition || !toolDefinition.execute) {
throw new Error(`Tool ${toolName} not found or not executable`);
}
// Actual testing might need more complex mocking to match the MCP SDK context
return toolDefinition.execute(params, {} as any);
}
describe('My Custom Tool Tests', () => {
beforeAll(async () => {
// Load test model data (if needed)
await loadModels('zh'); // Load Chinese models
});
test('get-model-count-by-category should return correct count', async () => {
const response = await callTool('get-model-count-by-category', { category: 'Decision Making', lang: 'zh' });
const result = JSON.parse(response.content[0].text);
expect(result.category).toBe('Decision Making');
expect(result.count).toBeGreaterThanOrEqual(0); // Specific count depends on your test data
});
});
运行测试
在 package.json 中配置测试脚本:
{
"scripts": {
"test": "jest"
}
}
然后运行:
npm test
构建与部署
构建项目
npm run build
此操作会使用 tsc(TypeScript 编译器)将 src 目录中的 .ts 文件编译为 JavaScript 文件,并放入 build 目录。
部署选项
部署为独立的 Node.js 服务
- 将整个项目(或至少将
build目录、node_modules、package.json 和 thinking_models_db)复制到服务器 - 运行服务:
node build/thinking_models_server.js - 或使用
pm2等进程管理器保持服务运行:npm install -g pm2 pm2 start build/thinking_models_server.js --name "thinking-models-mcp" pm2 save
编码规范
编码风格
- 遵循一致的编码风格(例如,使用 Prettier 和 ESLint)。
- 使用 TypeScript 的强类型功能,除非绝对必要,否则避免使用
any。 - 编写清晰、易于理解的代码,并为复杂逻辑添加注释。
命名约定
- 函数和变量:
camelCase(例如,calculateSimilarity) - 类和接口:
PascalCase(例如,ThinkingModel、McpServer) - 常量:
UPPER_SNAKE_CASE(例如,DEFAULT_PORT) - 文件名:
snake_case.ts或kebab-case.ts(在项目中保持一致)
文档规范
- 为所有公共 API(函数、类、接口)编写 JSDoc/TSDoc 注释。
- 在 README 和其他文档中清晰说明项目的功能和用法。
- 确保文档与代码保持同步。
常见开发问题与故障排查
1. 模型文件未加载或加载出错
- 检查路径:确保
SUPPORTED_LANGUAGES中定义的路径相对于编译后的thinking_models_server.js文件是正确的。 - JSON 格式:确保所有模型
.json文件都是有效的 JSON,并符合ThinkingModel接口的结构。 - 文件权限:确保服务进程有权限读取模型目录和文件。
- 日志:查看服务启动日志,加载模型时通常会在其中包含错误信息。
2. API 请求失败或找不到工具
- 服务运行状态:确认服务已成功启动且没有错误。
- 工具名称:确认客户端调用的工具名称与服务中注册的名称完全一致(区分大小写)。
- 参数格式:确保发送给工具的参数符合其 Zod 模式定义。
3. 相似度计算或推荐不准确
- 模型数据质量:
definition、purpose、tags、keywords等字段对相似度计算至关重要。确保这些字段内容丰富且准确。 - 算法调整:你可能需要调整
similarity_engine.ts中的算法参数或权重。 - 学习系统:如果启用了学习系统,请检查反馈数据是否已正确记录并应用。
最佳实践
- 日志记录:使用
log()函数(或更完善的日志库)记录关键操作、错误和调试信息。 - 错误处理:在所有工具函数和异步操作中实现健壮的错误处理,并向客户端返回有意义的错误消息。
- 模块化:将不同功能(例如相似度计算、学习系统、工具实现)组织到独立模块中。
- 配置管理:使用环境变量或配置文件管理端口和路径等可配置项。
许可证
本项目基于 MIT 许可证开源。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。