Community程式設計與開發github.com

MCP 應用程式建構器

**所有 MCP 伺服器工作的必備技能** - mcp-use 框架的最佳實踐與模式。在進行任何 MCP 伺服器工作前,請務必優先閱讀此技能。

MCP 應用程式建構器 是什麼?

這項技能對於任何使用 mcp-use 框架進行 MCP 伺服器開發的開發者或 AI 代理來說,是至關重要的參考與指南。它提供了一套全面的導航系統,幫助您根據當前任務(無論是建立新專案、新增驗證、實作伺服器功能,還是開發互動式 UI 小工具)找到正確的文件。其核心價值在於,它不僅整理了「要做什麼」,更強調了「不該做什麼」,明確列出常見的錯誤模式(如錯誤處理不當、安全性漏洞),並訂立了如「一個工具只做一件事」、「回傳完整資料」、「小工具管理自身狀態」等黃金法則,以確保開發出的 MCP 伺服器品質高、安全性強且易於維護。支援的平台包含基於 mcp-use 框架的所有 MCP 伺服器,例如在 Claude Code、Cursor 或 Codex 中使用的伺服器。這項技能本身作為一份導航圖,引導使用者閱讀架構、概念、工具、資源、提示與小工具等更詳細的參考文件,讓開發流程更具生產力且不易出錯。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/generative_ui_agents/ai-mcp-app-builder/apps/mcp-use-server/.agent/skills/mcp-apps-builder

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

重要事項:如何使用此技能

本檔案僅提供導航指南。在實作任何 MCP 伺服器功能之前,您必須:

  1. 閱讀此概覽以了解哪些參考檔案與您相關
  2. 務必閱讀與您要實作功能相關的特定參考檔案
  3. 將這些檔案中的詳細模式應用於您的實作中

請勿僅依賴本檔案中的快速參考範例——它們只是最小範例。參考檔案中包含了關鍵的最佳實踐、安全考量和進階模式。


MCP 伺服器最佳實踐

使用 mcp-use 建構具備工具、資源、提示和小工具之正式環境 MCP 伺服器的完整指南。

⚠️ 第一步:新專案或既有專案?

在執行任何操作之前,請先判斷您是否處於一個既有的 mcp-use 專案中。

判斷方式: 檢查工作區中是否有 package.json 檔案包含 "mcp-use" 作為相依套件,或者是否有任何 .ts 檔案從 "mcp-use/server" 匯入。

├─ 找到 mcp-use 專案 → 請勿重新建立。您已處於專案中。
│  └─ 跳至下方的「快速導航」以新增功能。
│
├─ 沒有 mcp-use 專案(空目錄、無關專案或全新專案)
│  └─ 請先使用 npx create-mcp-use-app 建立專案,然後再新增功能。
│     請參閱下方的「建立新專案」。
│
└─ 位於一個**無關的專案**(例如 Next.js 應用程式)中,且使用者想要一個 MCP 伺服器
   └─ 詢問使用者要在何處建立,然後在該目錄中建立專案。
      請勿在既有的無關專案根目錄內建立。

切勿手動建立 MCPServer 樣板、package.json 或專案結構。 CLI 會設定 TypeScript 配置、開發腳本、檢查器整合、熱重載以及小工具編譯,這些都很難手動複製。


建立新專案

npx create-mcp-use-app my-server
cd my-server
npm run dev

如需完整的建立細節和 CLI 標誌,請參閱 quickstart.md。


快速導航

根據您正在建構的內容選擇您的路徑:

🚀 基礎知識

何時閱讀: 在新的對話中開始 MCP 工作時務必先閱讀這些內容。後續可作為架構/概念澄清的參考。

  1. concepts.md - MCP 基礎元件(工具、資源、提示、小工具)以及何時使用
  2. architecture.md - 伺服器結構(基於 Hono)、中介軟體系統、server.use() vs server.app
  3. quickstart.md - 建立、設定和第一個工具範例
  4. deployment.md - 部署至 Manufact Cloud、自架、Docker、管理部署

在深入了解工具/資源/小工具區塊之前,請先載入這些文件。


🔐 新增驗證?

何時需要: 使用 OAuth(WorkOS、Supabase 或自訂)保護伺服器

  • overview.md

    • 何時閱讀:首次新增驗證、了解 ctx.auth,或選擇提供商
    • 涵蓋內容:oauth 配置、使用者上下文結構、提供商比較、常見錯誤
  • workos.md

    • 何時閱讀:使用 WorkOS AuthKit 進行驗證
    • 涵蓋內容:設定、環境變數、DCR vs 預先註冊、角色/權限、WorkOS API 呼叫
  • supabase.md

    • 何時閱讀:使用 Supabase 進行驗證
    • 涵蓋內容:設定、環境變數、HS256 vs ES256、支援 RLS 的 API 呼叫
  • custom.md

    • 何時閱讀:使用任何其他身分提供者(GitHub、Okta、Azure AD、Google 等)
    • 涵蓋內容:自訂驗證、使用者資訊提取、提供者範例

🔧 建構伺服器後端(無 UI)?

何時需要: 實作 MCP 功能(動作、資料、範本)。根據您正在建構的基礎元件閱讀特定檔案。

  • tools.md

    • 何時閱讀:建立 AI 可以呼叫的後端動作(發送郵件、擷取資料、建立使用者)
    • 涵蓋內容:工具定義、結構描述、註解、上下文、錯誤處理
  • resources.md

    • 何時閱讀:公開客戶端可擷取的唯讀資料(配置、使用者設定檔、文件)
    • 涵蓋內容:靜態資源、動態資源、參數化資源範本、URI 補全
  • prompts.md

    • 何時閱讀:建立供 AI 互動使用的可重複使用訊息範本(程式碼審查、摘要)
    • 涵蓋內容:提示定義、參數化、引數補全、提示最佳實踐
  • response-helpers.md

    • 何時閱讀:格式化工具/資源的回應(文字、JSON、Markdown、圖片、錯誤)
    • 涵蓋內容:text()、object()、markdown()、image()、error()、mix()

🎨 建構視覺化小工具(互動式 UI)?

何時需要: 建立用於瀏覽、比較或選取資料的 React 視覺化介面

  • basics.md

    • 何時閱讀:建立您的第一個小工具或為現有工具新增 UI
    • 涵蓋內容:小工具設定、useWidget() 鉤子、isPending 檢查、屬性處理
  • state.md

    • 何時閱讀:管理小工具內的 UI 狀態(選取、篩選、頁籤)
    • 涵蓋內容:useState、setState、狀態持久化、何時使用工具狀態 vs 小工具狀態
  • interactivity.md

    • 何時閱讀:在小工具內新增按鈕、表單或呼叫工具
    • 涵蓋內容:useCallTool()、表單處理、動作按鈕、樂觀更新
  • ui-guidelines.md

    • 何時閱讀:設計小工具樣式以支援主題、響應式佈局或無障礙性
    • 涵蓋內容:useWidgetTheme()、淺色/深色模式、autoSize、佈局模式、CSS 最佳實踐
  • advanced.md

    • 何時閱讀:建構具有非同步資料、錯誤邊界或效能最佳化的複雜小工具
    • 涵蓋內容:載入狀態、錯誤處理、記憶化、程式碼分割

📚 需要完整的範例?

何時需要: 您想查看常見使用案例的完整實作

  • common-patterns.md
    • 端到端範例:天氣應用程式、待辦事項清單、食譜瀏覽器
    • 展示:伺服器程式碼 + 小工具程式碼 + 情境中的最佳實踐

決策樹

您需要什麼?

├─ 全新的專案
│  └─> quickstart.md(建立 + 設定)
│
├─ OAuth / 使用者驗證
│  └─> authentication/overview.md → 特定提供商指南
│
├─ 簡單的後端動作(無 UI)
│  └─> 使用工具:server/tools.md
│
├─ 客戶端的唯讀資料
│  └─> 使用資源:server/resources.md
│
├─ 可重複使用的提示範本
│  └─> 使用提示:server/prompts.md
│
├─ 視覺化/互動式 UI
│  └─> 使用小工具:widgets/basics.md
│
└─ 部署至正式環境
   └─> deployment.md(雲端部署、自架、Docker)

核心原則

  1. 工具用於動作 - 具有輸入/輸出的後端操作
  2. 資源用於資料 - 客戶端可擷取的唯讀資料
  3. 提示用於範本 - 可重複使用的訊息範本
  4. 小工具用於 UI - 在需要時提供視覺化介面
  5. 先使用模擬資料 - 快速原型,之後再連接 API

❌ 常見錯誤

避免在正式環境 MCP 伺服器中發現的這些反模式:

工具定義

  • ❌ 回傳原始物件而非使用回應輔助函式
    • ✅ 使用 text()、object()、widget()、error() 輔助函式
  • ❌ 跳過每個欄位的 Zod 結構描述 .describe()
    • ✅ 為所有結構描述欄位新增描述,以便 AI 更好地理解
  • ❌ 沒有輸入驗證或清理
    • ✅ 使用 Zod 驗證輸入,清理使用者提供的資料
  • ❌ 拋出錯誤而非回傳 error() 輔助函式
    • ✅ 使用 error("訊息") 以優雅地回應錯誤

小工具開發

  • ❌ 在未檢查 isPending 的情況下存取 props
    • ✅ 始終檢查 if (isPending) return <Loading/>
  • ❌ 小工具處理伺服器狀態(篩選、選取)
    • ✅ 小工具使用 useState 管理自己的 UI 狀態
  • ❌ 缺少 McpUseProvider 包裝器或 autoSize
    • ✅ 包裝根元件:<McpUseProvider autoSize>
  • ❌ 內聯樣式沒有主題感知
    • ✅ 使用 useWidgetTheme() 以支援淺色/深色模式

安全性與正式環境

  • ❌ 在程式碼中硬編碼 API 金鑰或機密
    • ✅ 使用 process.env.API_KEY,在 .env.example 中記錄
  • ❌ 工具處理程式中沒有錯誤處理
    • ✅ 包裝在 try/catch 中,失敗時回傳 error()
  • ❌ 成本高昂的操作沒有快取
    • ✅ 快取 API 呼叫、計算,並設定 TTL
  • ❌ 缺少 CORS 配置
    • ✅ 為正式環境部署配置 CORS

🔒 黃金法則

強烈建議的架構指南:

1. 一個工具 = 一個功能

將寬泛的動作拆分為專注的工具:

  • ❌ manage-users(太模糊)
  • ✅ create-user、delete-user、list-users

2. 立即回傳完整資料

工具呼叫的成本很高。避免延遲載入:

  • ❌ list-products + get-product-details(2 次呼叫)
  • ✅ list-products 回傳包含詳細資訊的完整資料

3. 小工具擁有自己的狀態

UI 狀態存在於小工具中,而不是單獨的工具中:

  • ❌ select-item 工具、set-filter 工具
  • ✅ 小工具使用 useState 或 setState 管理

4. exposeAsTool 預設為 false

小工具預設僅註冊為資源。使用自訂工具(建議)或設定 exposeAsTool: true 來向模型公開小工具:

// ✅ 需要所有 4 個步驟才能正確進行類型推斷:

// 步驟 1:分別定義結構描述
const propsSchema = z.object({
  title: z.string(),
  items: z.array(z.string()),
});

// 步驟 2:在中繼資料中引用結構描述變數
export const widgetMetadata: WidgetMetadata = {
  description: "...",
  props: propsSchema, // ← 不要用內聯的 z.object()
  exposeAsTool: false,
};

// 步驟 3:從結構描述變數推斷 Props 類型
type Props = z.infer<typeof propsSchema>;

// 步驟 4:使用帶有類型參數的 useWidget
export default function MyWidget() {
  const { props, isPending } = useWidget<Props>(); // ← 新增 <Props>
  // ...
}

⚠️ 常見錯誤: 只做步驟 1-2 但跳過步驟 3-4(失去類型安全性)

5. 僅在邊界處驗證

  • 信任內部程式碼和框架保證
  • 驗證使用者輸入、外部 API 回應
  • 不要為不可能發生的情境新增錯誤處理

6. 偏好使用小工具進行瀏覽/比較

有疑問時,新增一個小工具。視覺化 UI 能改善:

  • 瀏覽多個項目
  • 並排比較資料
  • 互動式選取工作流程

快速參考

最小伺服器

import { MCPServer, text } from "mcp-use/server";
import { z } from "zod";

const server = new MCPServer({
  name: "my-server",
  title: "My Server",
  version: "1.0.0",
});

server.tool(
  {
    name: "greet",
    description: "問候使用者",
    schema: z.object({ name: z.string().describe("使用者的名稱") }),
  },
  async ({ name }) => text("Hello " + name + "!"),
);

server.listen();

回應輔助函式

輔助函式使用時機範例
text()簡單字串回應text("成功!")
object()結構化資料object({ status: "ok" })
markdown()格式化文字markdown("# 標題\n內容")
widget()視覺化 UIwidget({ props: {...}, output: text(...) })
mix()多個內容mix(text("嗨"), image(url))
error()錯誤回應error("無法擷取資料")
resource()嵌入資源參考resource("docs://guide", "text/markdown")

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

academic-researcher

Academic research assistant for literature reviews, paper analysis, and scholarly writing. Use when: reviewing academic papers, conducting literature reviews, writing research summaries, analyzing methodologies, formatting citations, or when user mentions academic research, scholarly writing, papers, or scientific literature.

chatgpt-app-builder

DEPRECATED: This skill has been replaced by `mcp-app-builder`. Check if `mcp-app-builder` is available in the skills folder. If not, install it: `npx skills install mcp-use/mcp-use --skill mcp-app-builder` Use `mcp-app-builder` instead of this skill. Build ChatGPT apps with interactive widgets using mcp-use and OpenAI Apps SDK. Use when creating ChatGPT apps, building MCP servers with widgets, defining React widgets, working with Apps SDK, or when user mentions ChatGPT widgets, mcp-use widgets, or Apps SDK development.

code-reviewer

Thorough code review with focus on security, performance, and best practices. Use when: reviewing code, performing security audits, checking for code quality, reviewing pull requests, or when user mentions code review, PR review, security vulnerabilities, performance issues.

content-creator

Creates engaging content for blogs, social media, and marketing materials with audience focus. Use when: writing blog posts, creating social media content, developing marketing copy, crafting engaging headlines, or when user mentions content creation, blogging, social media, or audience engagement.

content-writer

Writes marketing copy for landing pages, emails, and social media posts. Use when creating promotional content, sales copy, or brand messaging.

data-analyst

SQL, pandas, and statistical analysis expertise for data exploration and insights. Use when: analyzing data, writing SQL queries, using pandas, performing statistical analysis, or when user mentions data analysis, SQL, pandas, statistics, or needs help exploring datasets.

debugger

Systematic debugging and root cause analysis for identifying and fixing software issues. Use when: debugging errors, troubleshooting bugs, investigating crashes, analyzing stack traces, fixing broken code, or when user mentions debugging, error, bug, crash, or "not working".

decision-helper

Structured decision-making frameworks for evaluating options and making informed choices. Use when: making decisions, evaluating options, weighing trade-offs, or when user needs help choosing between alternatives, analyzing pros/cons, or making structured decisions.

deep-research

Comprehensive research assistant that synthesizes information from multiple sources with citations. Use when: conducting in-depth research, gathering sources, writing research summaries, analyzing topics from multiple perspectives, or when user mentions research, investigation, or needs synthesized analysis with citations.

editor

Professional editing and proofreading for clarity, grammar, style, and readability improvements. Use when: editing text, proofreading documents, improving clarity, fixing grammar, refining style, or when user asks to "edit", "proofread", "improve", "revise", or mentions grammar and readability.

email-drafter

Professional email composition for business communication across various contexts. Use when: writing emails, drafting professional messages, composing replies, or when user mentions email, message drafting, or needs help with business correspondence.

fact-checker

Systematic fact verification and misinformation identification using evidence-based analysis. Use when: verifying claims, checking facts, identifying misinformation, evaluating source credibility, or when user asks to "fact check", "verify", "is this true", or mentions claims that need validation.

fullstack-developer

Modern web development expertise covering React, Node.js, databases, and full-stack architecture. Use when: building web applications, developing APIs, creating frontends, setting up databases, deploying web apps, or when user mentions React, Next.js, Express, REST API, GraphQL, MongoDB, PostgreSQL, or full-stack development.

mcp-builder

DEPRECATED: This skill has been replaced by `mcp-app-builder`. Check if `mcp-app-builder` is available in the skills folder. If not, install it: `npx skills install mcp-use/mcp-use --skill mcp-app-builder` Use `mcp-app-builder` instead of this skill. Build Model Context Protocol (MCP) servers with mcp-use framework. Use when creating MCP servers, defining tools/resources/prompts, working with mcp-use, bootstrapping MCP projects, or when user mentions MCP development, tools, resources, or prompts.

meeting-notes

Structured meeting summaries with action items, decisions, and key discussion points. Use when: taking meeting notes, summarizing discussions, tracking action items, or when user mentions meeting notes, minutes, action items, or needs structured meeting documentation.

project-planner

Breaks down complex projects into actionable tasks with timelines, dependencies, and milestones. Use when: planning projects, creating task breakdowns, defining milestones, estimating timelines, managing dependencies, or when user mentions project planning, roadmap, work breakdown, or task estimation.

python-expert

Senior Python developer expertise for writing clean, efficient, and well-documented code. Use when: writing Python code, optimizing Python scripts, reviewing Python code for best practices, debugging Python issues, implementing type hints, or when user mentions Python, PEP 8, or needs help with Python data structures and algorithms.

sprint-planner

Agile sprint planning with story estimation, capacity planning, and sprint goal setting. Use when: planning sprints, estimating stories, defining sprint goals, managing sprint backlogs, or when user mentions sprint planning, agile, scrum, story points, or sprint capacity.

strategy-advisor

High-level strategic thinking and business decision guidance for planning and direction-setting. Use when: making strategic decisions, evaluating business options, setting direction, analyzing trade-offs, or when user mentions strategy, business planning, competitive analysis, or long-term planning.

technical-writer

Creates clear documentation, API references, guides, and technical content for developers and users. Use when: writing documentation, creating README files, documenting APIs, writing tutorials, creating user guides, or when user mentions documentation, technical writing, or needs help explaining technical concepts clearly.

相關技能