深圳企业网站建设推荐公司,最佳外贸建站平台,做好网络推广,wordpress做登陆界面也是在学习中...
起因#xff1a;
抖音博客 艾克AI分享 他的视频 #143《Claude开源MCP彻底打破AI的信息孤岛》 提到: Claude开源的MCP太强了#xff0c;视频后面是快速演示#xff0c;反正看了好几遍也没弄明白。菜单都不一样#xff0c;感觉用的不是同一家 Claude. 探…也是在学习中...
起因
抖音博客 艾克AI分享 他的视频 #143《Claude开源MCP彻底打破AI的信息孤岛》 提到: Claude开源的MCP太强了视频后面是快速演示反正看了好几遍也没弄明白。菜单都不一样感觉用的不是同一家 Claude. 探索
有用的信息有源TUTORIAL: GET MCP WORKING ON WINDOWS (教程在 Windows 上运行 MCP)
1. 什么是 MCP
MCPClaude Model Context Protocol 暂定义为 模型关联(上下方)协议
信息来源Introducing the Model Context Protocol \ Anthropic 几段翻译
“今天我们开源了 Model Context ProtocolMCP这是一个将人工智能助手与数据存储系统包括内容库、业务工具和开发环境连接的新标准。其目的是帮助前沿模型生成更好、更相关的响应。”
“MCP 解决了这个挑战(模型与数据隔离)。它提供了一种通用的开放标准用于将 AI 系统与数据源连接取代了分散的集成使用单一协议。结果是为 AI 系统提供所需数据的方式更简单、更可靠。”
“MCP是一种开放标准使开发者能够在他们的数据源和人工智能工具之间建立安全的双向连接。架构很简单开发者可以通过 MCP 服务器公开他们的数据或者构建连接到这些服务器的人工智能应用程序MCP 客户端。”
MCP 三个主要组成部分:
MCP规范和 SDK本地的 MCP 服务器支持在 Claude Desktop App. 点右侧下载Claude Desktop Apps一个开源的 MCP 服务器库
2. 开始构建第一个 MCP 服务器
信息来源https://modelcontextprotocol.io/quickstart
我想省略这部分但看到这个实践过程小于5分钟还是代手翻译一下。
MCP 是一种协议能够在主机应用程序如 Claude Desktop和本地服务之间建立安全连接。
“Claude Desktop’s MCP support is currently in developer preview and only supports connecting to local MCP servers running on your machine. Remote MCP connections are not yet supported. This integration is only available in the Claude Desktop app, not the Claude web interface (claude.ai).” 仅集成在 Claude Desktop App网页不行。 所以要安装 Claude Desktop Apps
a. MCP 如何工作
MCP 实现 AI 应用程序与本地或远程资源之间的安全的、受控的对话。
i. 总体架构
在其核心MCP 遵循客户端-服务器架构其中主机应用程序可以连接到多个服务器 来自https://modelcontextprotocol.io/quickstart 这里有几个名字解释
MCP Hosts 程序如 Claude Desktop、IDE 或者 AI 工具希望通过 MCP 访问资源MCP Clients保持着与服务器1对1的连接的协议客户端MCP Servers: 通过标准化的 MCP 协议展露特定功能的每个轻量级程序。Local Resources: MCP servers 能访问的你的计算机上的资源如数据库文档应用/系统 服务Remote Resources: MCP Servers能通过互联网连接到的可用资源如APIs
ii. 实践 1 使用 SQLite
使用 SQLite 实现一个示例 在我的windows 11上操作 来自 Quickstart - Model Context Protocol MCP ClientClaude Desktop AppMCP ServerSQLlite 提供数据库的访问Local Resource: 本地的 SQLite 数据库
1准备环境
安装 Claude Desktop App 还有 uvPython 包管理器和虚拟环境工具SQLite轻量级的关系型数据库管理系统Git 版本控制系统
# Using winget
winget install --idastral-sh.uv -e
winget install git.git sqlite.sqlite# Or download directly:
# uv: https://docs.astral.sh/uv/
# Git: https://git-scm.com
# SQLite: https://www.sqlite.org/download.html
把上面框里不带 # 开头的每行在 CMD 运行去安装
C:\Users\davewinget install --idastral-sh.uv -e
The msstore source requires that you view the following agreements before using.
Terms of Transaction: https://aka.ms/microsoft-store-terms-of-transaction
The source requires the current machines 2-letter geographic region to be sent to the backend service to function properly (ex. US).Do you agree to all the source agreements terms?
[Y] Yes [N] No: y
Found uv [astral-sh.uv] Version 0.5.5
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
This package requires the following dependencies:- PackagesMicrosoft.VCRedist.2015.x64
Downloading https://github.com/astral-sh/uv/releases/download/0.5.5/uv-x86_64-pc-windows-msvc.zip██████████████████████████████ 14.4 MB / 14.4 MB
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package install...
Path environment variable modified; restart your shell to use the new value.
Command line alias added: uv
Command line alias added: uvx
Successfully installed
C:\Users\davewinget install git.git sqlite.sqlite
(1/2) Found Git [Git.Git] Version 2.47.1
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.1/Git-2.47.1-64-bit.exe██████████████████████████████ 65.9 MB / 65.9 MB
Successfully verified installer hash
Starting package install...
The installer will request to run as administrator, expect a prompt.
Successfully installed(2/2) Found SQLite [SQLite.SQLite] Version 3.47.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://www.sqlite.org/2024/sqlite-tools-win-x64-3470000.zip██████████████████████████████ 6.04 MB / 6.04 MB
Successfully verified installer hash
Extracting archive...
Successfully extracted archive
Starting package install...
Path environment variable modified; restart your shell to use the new value.
Command line alias added: sqldiff
Command line alias added: sqlite3_analyzer
Command line alias added: sqlite3
Successfully installed
2创建一个样本数据库
以下是复制于指南的这是 power shell 命令格式 创建一个 create_db.ps1 文件:
Z:\mkdir practiceZ:\cd practiceZ:\practicenotepad create_db.ps1Z:\practice
把以下内容复制到 create_db.ps1 文件里
# Create a new SQLite database
$sql
CREATE TABLE products (id INTEGER PRIMARY KEY,name TEXT,price REAL
);INSERT INTO products (name, price) VALUES(Widget, 19.99),(Gadget, 29.99),(Gizmo, 39.99),(Smart Watch, 199.99),(Wireless Earbuds, 89.99),(Portable Charger, 24.99),(Bluetooth Speaker, 79.99),(Phone Stand, 15.99),(Laptop Sleeve, 34.99),(Mini Drone, 299.99),(LED Desk Lamp, 45.99),(Keyboard, 129.99),(Mouse Pad, 12.99),(USB Hub, 49.99),(Webcam, 69.99),(Screen Protector, 9.99),(Travel Adapter, 27.99),(Gaming Headset, 159.99),(Fitness Tracker, 119.99),(Portable SSD, 179.99);
cd ~sqlite3 test.db $sql在 power shell 里运行这个文件会去创建一个 text.db 数据库 包含 为 products 表其有20条记录还可以用 sqlite3 打开应用在里面用 命令行操作略...
3配置 Claude Desktop
在文本编辑器中打开 %APPDATA%\Claude\claude_desktop_config.json 文件 Claude Desktop 应用的配置
因为我的 Windows 11 上有安装 VS code可以在 CMD 打开这个配置文件
PS C:\Users\dave code $env:AppData\Roaming\Claude\claude_desktop_config.json
注1: 你需要查看 Claude Desktop 安装目录 指南上是“$env:AppData\Claude\claude_desktop_config.json” 我的 Win 11的位置是上面的。 注2: 在我的 Claude 目录下并没有 claude_desktop_config.json 这个文件。
添加以下内容到 json 文件替换 YOUR_USERNAME
{mcpServers: {sqlite: {command: uvx,args: [mcp-server-sqlite,--db-path,Z:\\practice\\test.db]}}
}让 Claude Desktop 去连接刚才创建的 test.db 数据库。现在就可以保存 json 文件并重启 Claude Desktop我是用 Task Manger 去找到 Claude.exe 右键 end task再点图标 注 Norton 会检测 Claude Desktop App 有病毒需要做 exception 操作。 4验证
再次起动 Claude Desktop App,
原文章中的 Prompt:
Can you connect to my SQLite database and tell me what products are available, and their prices?执行时会有一个 CMD 窗口来运行 uvx mcp-server-sqlite --db-path 连接数据库不要关闭还会遇到授权 C:\Users\davesqlite3
SQLite version 3.47.0 2024-10-21 16:30:22
Enter .help for usage hints.
Connected to a transient in-memory database.
Use .open FILENAME to reopen on a persistent database.
sqlite .open test.db
sqlite .schema table_name
sqlite SELECT * FROM sqlite_master WHERE typetable;
table|products|products|2|CREATE TABLE products (id INTEGER PRIMARY KEY,name TEXT,price REAL
)
table|orders|orders|3|CREATE TABLE orders (order_id INTEGER PRIMARY KEY,customer_name TEXT NOT NULL,customer_email TEXT,product_id INTEGER,quantity INTEGER NOT NULL DEFAULT 1,order_date DATETIME DEFAULT CURRENT_TIMESTAMP,total_amount REAL NOT NULL,status TEXT DEFAULT pending,shipping_address TEXT,FOREIGN KEY (product_id) REFERENCES products(id)
)
sqlite
5小结
查询表中内容、创建新表都可以用 prompt 来执行中英文都行。
iii. 实践 2 访问文件系统
1准备环境安装 Node.js, uv 工具
在电脑上运行 JavaScript 代码需要 Node.js 链接是下载 LTS 版.
npx 需要 uv tools : Tools | uv
2配置 Claude Desktop
添加以下内容到 claude_desktop_config.json 文件: (替换YOUR_USERNAME 为 你的实际 用户名)你也可以设置为其它路径。我这里用的是 claude-server 文件夹。
filesystem: {command: npx,args: [/c, modelcontextprotocol/server-filesystem, /Users/YOUR_USERNAME/claude-server]
}3配置文件index.ts package.json tsconfig.json
servers/src/filesystem at main · dave2nian/servers · GitHub
上面三个文件带有链接下载后放后你需要 Claude AI 访问的目录。我实践用的是 C:\Users\dave\claude-server
然后安装 NODE 依赖库命令如下
cd C:\Users\dave\claude-server npm install
注 package.json 中有写需要的库 或者用 npm install express 也行。
4验证
结束所有的 Claude.exe 进程与node.exe 进程如果有再次启动 Claude Desktop App 如果在对话框中有“小锤子” 我删除了 SQLite只保留 Filesystem 所以是9个功能。 借用我在 GITHUB posts.
prompt: to create a text file that name is greeting with content hello word! in my folder
Claude Desktop app 利用 node.js 在我的计算机上创建了一个文本文件并内容是 “Hello Word! (想起以前学 basicII )
重点是 我在网上看到的所有其实就2处 都是 -y 参数 一定要用 “/c 。 看我的配置文件里都用 debug 为这实现这个功能耗了两晚上。 added below on 4DEC2024:
iii. 实践 3 网络文件系统 windows mapping network driver
Claude 3 天前更新了 Claude Desktop 去修复了 npx 在 windows 上问题 如图 用我之前的配置也是可以正常工作的。
因为我的 laptop 只有一个 C 盘 其它的都是 NAS 的映射盘符这个实践来演示MCP filesystem 在 Windows 11 系统上如何实现文件系统访问
1准备环境同 实践ii
见上面。
2 配置 claude desktop 参考 z: mapping \\davens\\davens\Multimedia
目标目录Z:\2024-MyProgramFiles
Desktop 配置文件C:\Users\your windows ID/account\AppData\Roaming\Claude\claude_desktop_config.json
{mcpServers: {filesystem: {command: npx,args: [ -y, modelcontextprotocol/server-filesystem, \\\\davens\\Multimedia\\2024-MyProgramFiles]}}
}3node.js 三个配置文件
同 实践ii.3 提到的三个文件复制到 Z:\2024-MyProgramFiles 目录下就好。
4验证
Prompt: list local file 牢骚几句
本来写了一编个 AI 的比较 竟然说我打 广告 写了很多对比这审查制度是不是因为我没充值 没有设置收费