Cursor +MCP(Model Context Protocol)使用指南 -- 创建一个github MCP

最近,MCP(Model Context Protocol) 在 AI 和开发者社区中引起了广泛关注,它为大型语言模型(LLM) 提供了一种标准化的方式来与外部工具和服务交互,比如数据库(Redis)、GitHub 仓库、HTTP API 等。

本帖将记录 MCP 的安装、配置及常见使用方法,帮助开发者快速上手。

什么是 MCP?

你可以把 MCP(Model Context Protocol) 想象成AI 的“万能适配器”,它让 AI 能够与外部世界对话,就像你的电脑需要驱动程序来连接键盘、鼠标、打印机一样,MCP 就是 AI 连接 GitHub、Redis、数据库、API 等工具的**“驱动程序”**。

💡 形象比喻:

如果 AI 是一个聪明但“封闭”的人,它能读懂你给它的指令,但无法自己去上网搜索、访问数据库或者管理 GitHub 仓库。

MCP 就像是“扩展器”或者“翻译官”,它让 AI 可以:

直接访问 GitHub 仓库,管理代码。

操作 Redis 服务器,存取数据。

调用 HTTP API,与外部服务通信。

甚至访问本地文件,读取或修改内容。

简而言之,MCP 让 AI 具备了“动手能力”,让它不仅仅是个回答问题的助手,还能真正地执行任务!

一、 先要安装node.js

1. 访问官网https://nodejs.org/en 下载node.js 是先决条件

置环境变量
在path中配置:

PS C:\Users\thore> node -v
v22.14.0

PS C:\Users\thore> npx -v
npx : 无法加载文件 D:\soft\nodejs\npx.ps1。未对文件 D:\soft\nodejs\npx.ps1 进行数字签名。无法在当前系统上运行该脚本。…
永久修改执行策略:
PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
PS C:\WINDOWS\system32> npx -v
10.9.2

二、 在Cursor里的配置

1. 切换版本

在这里插入图片描述
通过设置到Beta,将现有的standard版本切换到Early Access版本

2. 检查版本是否更新

在”Help”中找到“Check for Updates”中检查新的版本
在这里插入图片描述
将cursor升级到最新的版本。

3. 选择创建MCP

“设置”->“MCP”找到创建MCP的界面
在这里插入图片描述

4. MCP文件的作用域

它是由文件来创建不同作用域的文件:
当前项目下创建MCP,那么将会在这个项目中使用,如果选择蓝色按钮将会在用户下创建MCP文件,这样的设置将是全局的。

三、 创建MCP文件的步骤

1. 在项目中创建一个MCP

1) 根目录下创建一个目录.cursor文件夹

2) 在.cursor文件夹内创建mcp.json文件

A. 查看官方的一些推荐MCP库

在这里插入图片描述
官方网址:https://github.com/modelcontextprotocol/servers

2. 创建GitHub MCP Server

1) Github创建一个自己的token

在这里插入图片描述

3. 创建Mcp文件

“github.com/modelcontextprotocol/servers/tree/main/src/github”: {
“command”: “cmd”,
“args”: [
“/c”,
“npx”,
“-y”,
“GITHUB_PERSONAL_ACCESS_TOKEN”,
“@modelcontextprotocol/server-github”
],
“env”: {
“GITHUB_PERSONAL_ACCESS_TOKEN”: “<YOUR_TOKEN>”
},
“disabled”: false,
“autoApprove”: []
}
}
}

注意:GITHUB_PERSONAL_ACCESS_TOKEN要填入自己github的token

保存,运行甚至让cursor尝试运行,就会有下面结果:

在这里插入图片描述
在这里插入图片描述
证明创建成功!

四、

1. GitHub MCP 功能 & 在 Cursor 上的使用方法

GitHub MCP 让 AI 能够与 GitHub 仓库交互,它提供了一系列 API,允许你直接在 Cursor 编辑器中管理 GitHub 代码仓库,比如列出仓库、读取文件、提交更改等。以下是它的主要功能以及如何在 Cursor 里使用。

2. 🌟 GitHub MCP 提供的功能

功能说明示例
列出仓库获取 GitHub 用户的所有仓库listRepos
获取仓库信息获取特定仓库的详细信息getRepoInfo
列出仓库文件获取指定仓库的文件列表listFiles
读取文件内容读取 GitHub 上的文件readFile
创建/更新文件在 GitHub 上创建或修改文件writeFile
删除文件从仓库中删除文件deleteFile
列出分支获取仓库的所有分支listBranches
创建分支从指定分支创建新分支createBranch
创建Pull Request 提交代码变更并创建 PRcreatePullRequest
列出Issues 获取仓库的所有 IssuelistIssues
创建Issue 在仓库中创建新的 IssuecreateIssue
发表评论在 Issue 或 PR 上发表评论addComment
  1. 🚀在 Cursor 里使用 GitHub MCP结合 AI 使用 MCP
    打开 Cursor,在根目录下找到 mcp.json 文件,并添加以下内容:
    AI: “帮我列出 GitHub 上的仓库。”

从测试结果来看:
MCP 服务器确实在运行(显示 “GitHub MCP Server running on stdio”)
我们成功获取到了您的 GitHub 仓库信息:
您有一个名为 “NebulaVerseAI” 的仓库
仓库 URL 是 https://github.com/Samuel521199/NebulaVerseAI
但是,我们也发现了一些问题:
MCP 客户端包(@modelcontextprotocol/client-github)不存在于 npm 注册表中
直接通过 HTTP 请求与服务器通信也遇到了一些问题
建议:
继续使用服务器端命令来获取 GitHub 信息
如果需要更多功能,我们可以:
查找正确的客户端包
或者直接使用 GitHub API

五、 参考其他各种功能的服务器

These servers aim to demonstrate MCP features and the TypeScript and Python SDKs.
• AWS KB Retrieval - Retrieval from AWS Knowledge Base using Bedrock Agent Runtime
• Brave Search - Web and local search using Brave’s Search API
• EverArt - AI image generation using various models
• Everything - Reference / test server with prompts, resources, and tools
• Fetch - Web content fetching and conversion for efficient LLM usage
• Filesystem - Secure file operations with configurable access controls
• Git - Tools to read, search, and manipulate Git repositories
• GitHub - Repository management, file operations, and GitHub API integration
• GitLab - GitLab API, enabling project management
• Google Drive - File access and search capabilities for Google Drive
• Google Maps - Location services, directions, and place details
• Memory - Knowledge graph-based persistent memory system
• PostgreSQL - Read-only database access with schema inspection
• Puppeteer - Browser automation and web scraping
• Redis - Interact with Redis key-value stores
• Sentry - Retrieving and analyzing issues from Sentry.io
• Sequential Thinking - Dynamic and reflective problem-solving through thought sequences
• Slack - Channel management and messaging capabilities
• Sqlite - Database interaction and business intelligence capabilities
• Time - Time and timezone conversion capabilities

六、 其他类的第三方服务

🎖️ Official Integrations
Official integrations are maintained by companies building production ready MCP servers for their platforms.
• 21st.dev Magic - Create crafted UI components inspired by the best 21st.dev design engineers.
• Adfin - The only platform you need to get paid - all payments in one place, invoicing and accounting reconciliations with Adfin.
• AgentQL - Enable AI agents to get structured data from unstructured web with AgentQL.
• AgentRPC - Connect to any function, any language, across network boundaries using AgentRPC.
• Aiven - Navigate your Aiven projects and interact with the PostgreSQL®, Apache Kafka®, ClickHouse® and OpenSearch® services
• Apify - Actors MCP Server: Use 3,000+ pre-built cloud tools to extract data from websites, e-commerce, social media, search engines, maps, and more
• APIMatic MCP - APIMatic MCP Server is used to validate OpenAPI specifications using APIMatic. The server processes OpenAPI files and returns validation summaries by leveraging APIMatic’s API.
• Audiense Insights - Marketing insights and audience analysis from Audiense reports, covering demographic, cultural, influencer, and content engagement analysis.
• Axiom - Query and analyze your Axiom logs, traces, and all other event data in natural language
• Bankless Onchain - Query Onchain data, like ERC20 tokens, transaction history, smart contract state.
• BICScan - Risk score / asset holdings of EVM blockchain address (EOA, CA, ENS) and even domain names.
• Box - Interact with the Intelligent Content Management platform through Box AI.
• Browserbase - Automate browser interactions in the cloud (e.g. web navigation, data extraction, form filling, and more)
• Chargebee - MCP Server that connects AI agents to Chargebee platform.
• Chroma - Embeddings, vector search, document storage, and full-text search with the open-source AI application database
• Chronulus AI - Predict anything with Chronulus AI forecasting and prediction agents.
• ClickHouse - Query your ClickHouse database server.
• Cloudflare - Deploy, configure & interrogate your resources on the Cloudflare developer platform (e.g. Workers/KV/R2/D1)
• Comet Opik - Query and analyze your Opik logs, traces, prompts and all other telemtry data from your LLMs in natural language.
• Convex - Introspect and query your apps deployed to Convex.
• Dart - Interact with task, doc, and project data in Dart, an AI-native project management tool
• DevHub - Manage and utilize website content within the DevHub CMS platform
• E2B - Run code in secure sandboxes hosted by E2B
• EduBase - Interact with EduBase, a comprehensive e-learning platform with advanced quizzing, exam management, and content organization capabilities
• eSignatures - Contract and template management for drafting, reviewing, and sending binding contracts.
• Exa - Search Engine made for AIs by Exa
• Fewsats - Enable AI Agents to purchase anything in a secure way using Fewsats
• Fibery - Perform queries and entity operations in your Fibery workspace.
• Financial Datasets - Stock market API made for AI agents
• Firecrawl - Extract web data with Firecrawl
• Fireproof - Immutable ledger database with live synchronization
• Gitee - Gitee API integration, repository, issue, and pull request management, and more.
• gotoHuman - Human-in-the-loop platform - Allow AI agents and automations to send requests for approval to your gotoHuman inbox.
• Grafana - Search dashboards, investigate incidents and query datasources in your Grafana instance
• Graphlit - Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a searchable Graphlit project.
• GreptimeDB - Provides AI assistants with a secure and structured way to explore and analyze data in GreptimeDB.
• Hologres - Connect to a Hologres instance, get table metadata, query and analyze data.
• Hyperbrowser - Hyperbrowser is the next-generation platform empowering AI agents and enabling effortless, scalable browser automation.
• IBM wxflows - Tool platform by IBM to build, test and deploy tools for any data source
• ForeverVM - Run Python in a code sandbox.
• Inbox Zero - AI personal assistant for email Inbox Zero
• Inkeep - RAG Search over your content powered by Inkeep
• Integration App - Interact with any other SaaS applications on behalf of your customers.
• JetBrains – Work on your code with JetBrains IDEs
• Kagi Search - Search the web using Kagi’s search API
• Keboola - Build robust data workflows, integrations, and analytics on a single intuitive platform.
• Logfire - Provides access to OpenTelemetry traces and metrics through Logfire.
• Langfuse Prompt Management - Open-source tool for collaborative editing, versioning, evaluating, and releasing prompts.
• Lingo.dev - Make your AI agent speak every language on the planet, using Lingo.dev Localization Engine.
• Mailgun - Interact with Mailgun API.
• Make - Turn your Make scenarios into callable tools for AI assistants.
• Meilisearch - Interact & query with Meilisearch (Full-text & semantic search API)
• Metoro - Query and interact with kubernetes environments monitored by Metoro
• Milvus - Search, Query and interact with data in your Milvus Vector Database.
• MotherDuck - Query and analyze data with MotherDuck and local DuckDB
• Needle - Production-ready RAG out of the box to search and retrieve data from your own documents.
• Neo4j - Neo4j graph database server (schema + read/write-cypher) and separate graph database backed memory
• Neon - Interact with the Neon serverless Postgres platform
• OceanBase - MCP Server for OceanBase database and its tools
• Octagon - Deliver real-time investment research with extensive private and public market data.
• Oxylabs - Scrape websites with Oxylabs Web API, supporting dynamic rendering and parsing for structured data extraction.
• Perplexity - An MCP server that connects to Perplexity’s Sonar API, enabling real-time web-wide research in conversational AI.
• Qdrant - Implement semantic memory layer on top of the Qdrant vector search engine
• Ramp - Interact with Ramp’s Developer API to run analysis on your spend and gain insights leveraging LLMs
• Raygun - Interact with your crash reporting and real using monitoring data on your Raygun account
• Rember - Create spaced repetition flashcards in Rember to remember anything you learn in your chats
• Riza - Arbitrary code execution and tool-use platform for LLMs by Riza
• Search1API - One API for Search, Crawling, and Sitemaps
• ScreenshotOne - Render website screenshots with ScreenshotOne
• Semgrep - Enable AI agents to secure code with Semgrep.
• SingleStore - Interact with the SingleStore database platform
• StarRocks - Interact with StarRocks
• Stripe - Interact with Stripe API
• Tavily - Search engine for AI agents (search + extract) powered by Tavily
• Thirdweb - Read/write to over 2k blockchains, enabling data querying, contract analysis/deployment, and transaction execution, powered by Thirdweb
• Tinybird - Interact with Tinybird serverless ClickHouse platform
• UnifAI - Dynamically search and call tools using UnifAI Network
• Unstructured - Set up and interact with your unstructured data processing workflows in Unstructured Platform
• Vectorize - Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
• Verodat - Interact with Verodat AI Ready Data platform
• VeyraX - Single tool to control all 100+ API integrations, and UI components
• Xero - Interact with the accounting data in your business using our official MCP server
• Zapier - Connect your AI Agents to 8,000 apps instantly.
• ZenML - Interact with your MLOps and LLMOps pipelines through your ZenML MCP server

### 关于 CursorMCP 的技术概念或用法 #### 定义与背景 MCP(Master Control Program)是一种多线程操作系统,通常运行在 Burroughs 大型机上。它支持高级别的并发性和复杂的内存管理机制[^1]。Cursor 是指一种数据结构或者操作符,在编程环境中常被用来表示当前处理的位置或者是某种状态指示器。 #### CursorMCP 编程中的角色 在 MCP 环境下,cursor 可能具有多种用途,具体取决于上下文环境以及应用程序的需求。以下是几个常见的应用场景: - **数据库访问**: 当通过 MCP 提供的接口连接到数据库时,cursor 被广泛应用于遍历查询结果集。例如,SQL 查询的结果可以通过 cursor 来逐行读取并进一步处理[^2]。 - **文件流控制**: 类似于其他现代操作系统上的文件句柄,cursorMCP 中也可以作为文件位置标记来使用。这使得开发者能够精确地定位到特定的数据块进行修改或检索[^3]。 - **图形界面交互**: 如果涉及到 GUI 应用开发,则 cursor 还可能代表鼠标光标的当前位置信息或其他形式的人机互动反馈信号[^4]。 ```python # 假设我们正在编写一段基于 MCP 平台的应用程序代码片段, # 下面展示了一个简单的如何利用 cursor 遍历记录列表的例子: def process_records(cursor): while not cursor.eof(): # eof() 方法判断是否到达末尾 record = cursor.read_next_record() handle_data(record) process_records(my_cursor_instance) ``` 上述伪代码展示了在一个假设性的 MCP API 上实现基本游标功能的方式——即循环调用 `read_next_record()` 函数直到遇到结束条件为止。 #### 技术细节探讨 对于更深入理解 cursor 和其在 MCP 编程里的实际应用来说,还需要考虑以下几个方面因素: - 错误处理策略: 如何优雅地捕获异常情况下的错误消息? - 性能优化技巧: 是否存在某些方法可以减少频繁磁盘I/O带来的开销? - 安全性考量: 数据隔离措施能否防止未经授权的操作? 这些问题都需要依据具体的业务场景做出相应的解答,并且往往伴随着丰富的实践经验积累才能完全掌握其中精髓所在。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值