Nilenso Blog 09月30日
MCP协议简化AI应用集成
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

MCP协议通过将M×N集成问题转化为M+N集成问题,解决了AI应用与平台间的集成难题。该协议定义了MCP服务器和客户端,服务器通常连接数据源并暴露特定工具,如文件系统访问或邮件发送;客户端则作为AI应用的一部分,可连接任何MCP服务器。服务器可提供工具调用接口、可重用的指令模板、资源URI和LLM采样功能。例如,作者创建了一个MCP服务器以访问CKAN开放数据平台,并通过配置使其在Claude桌面应用中可用,实现了AI对数据的分析和可视化。MCP协议通过解耦AI客户端与工具和工作流程,降低了集成复杂度,但其也需额外开发成本,且LLM性能受限于提示和工具描述。

🔧 MCP协议通过将M×N集成问题转化为M+N集成问题,简化了AI应用与不同平台的集成过程。它将复杂的集成需求分解为更小的、可管理的部分,降低了开发难度。

🖥️ MCP服务器作为数据源和工具的提供者,通常连接到特定平台(如CKAN数据管理系统),并暴露可被AI客户端调用的工具(如文件系统访问、邮件发送等)。客户端则作为AI应用的一部分,通过配置连接到这些服务器,实现跨平台数据访问和功能调用。

📈 作者以CKAN数据管理系统的MCP服务器为例,展示了如何通过编写服务器代码(使用官方Python SDK)并在客户端(如Claude桌面应用)中配置,实现AI对开放数据的访问和分析。这种‘门把手’式的接口使得多个AI应用和代理能够通用,促进了数据共享和AI能力的扩展。

📊 MCP服务器可提供多种功能,包括工具调用接口、可重用的指令模板(prompts)、资源URI访问和LLM采样,这些功能使AI应用能够更灵活地与外部系统交互,执行复杂任务(如数据搜索、资源详情获取等),并支持更高级的AI模式(如自主代理和情境感知推理)。

Model Context Protocol, like most protocols, solves the M ⨯ N integration problem by turning it into an M + N integration problem.

An AI client application that speaks this protocol does not have to figure out how to fetch data or take actions specific to a platform.

MCP may or may not make your AI smarter, or improve your product, but it will reduce the friction to integrate against other applications that already support MCP. This may or may not be important to you.

The protocol specifies MCP Servers, that generally connect to data sources and expose tools specific to it. Then there are MCP clients, which are a part of AI applications. They can connect to any MCP Server, typically through a configuration that specifies how to connect to or run the server.

The servers, more commonly implemented than clients, may expose:

There are a few more functions and nuances to servers, but these are what broadly stood out to me. Most servers that I have seen or used mostly just expose tool calls.

A tiny concrete example: an MCP server for Open Data access

I wrote a tiny MCP server to expose actions to take on CKAN, an open source data management system that’s used by Governments and other organisations to publish open datasets. CKAN has a web interface that links to these tagged datasets, which are usually semi-structured (CSVs, XLS) or totally unstructured (PDF reports and papers).

This is not particularly conducive to discovery and drilling through data. It’s also significant friction to connect dots across datasets. I thought it would be nice to have an AI application that can access all the datasets on CKAN and make sense of it. Open Data is as useful as the insights that can be extracted from it.

One way for me to have approached this is to write an AI application from scratch encoded with knowledge about all the CKAN REST APIs. Unfortunately, this would have “locked in” AI use of CKAN open data sets to just my application. And data, especially Open Data wants to be free.

What I really wanted is a well-known “doorknob” that a lot of AI applications and agents in the world would know how to open. This is what MCP servers do. I wrote one in a couple of hours.

I used the official MCP Python SDK and defined some tools. Here’s an excerpt of what that looks like:

@mcp.tool()async def list_tags(query: Optional[str] = None, limit: int = 50, ctx: Context = None) -> str:    """List available tags in CKAN.    Args:        query: Optional search string to filter tags        limit: Maximum number of tags to return    Returns:        A formatted string containing available tags.    """    # code to list all the tags used to tag data, via the CKAN API@mcp.tool()async def search_datasets(    query: Optional[str] = None,    tags: Optional[List[str]] = None,    organization: Optional[str] = None,    format: Optional[str] = None,    limit: int = 10,    offset: int = 0,    ctx: Context = None) -> str:    """Search for datasets with various filters.    Args:        query: Free text search query        tags: Filter by tags (list of tag names)        organization: Filter by organization name        format: Filter by resource format (e.g., CSV, JSON)        limit: Maximum number of datasets to return        offset: Number of datasets to skip    Returns:        A formatted string containing matching datasets.    """    # code to handle searches, using the CKAN API@mcp.tool()async def get_resource_details(resource_id: str, ctx: Context = None) -> str:    """Get detailed information about a specific resource (file/data).    Args:        resource_id: The ID of the resource    Returns:        A formatted string containing resource details.    """    # code to read the details and get the link to a specific resource, using the CKAN API

The details of the SDK are better explained in official guides, but the gist of it is that it is an abstraction over JSON-RPC request-response messages that are defined in the protocol. The server I have implemented runs locally, launched as a subprocess by the client app and uses the stdio streams to pass these protocol messages around. Remote MCP servers are a thing as well.

After I wrote this server, I exposed it to the Claude desktop app, which is also an MCP client by editing claude_desktop_config.json. I pointed it to JusticeHub, a CKAN instance that contains legal and justice data, created by the folks at CivicDataLabs.

{  "mcpServers": {    "CKAN Server": {      "command": "/Users/atharva/.local/bin/uv",      "args": [        "run",        "--with",        "httpx",        "--with",        "mcp[cli]",        "mcp",        "run",        "/Users/atharva/ckan-mcp-server/main.py"      ],      "env": {        "CKAN_URL": "https://justicehub.in"      }    }  }}

This allowed me to use this data through Claude.

Claude discovered my MCP server and gave me a summary of what kind of data was available in JusticeHub.

I was able to take advantage of Claude’s analysis tool to help me visualise the data in an interactive dashboard!

I can envision other MCP clients in the future that could make better use of this data, beyond this basic conversational interface and tackle problems such as backlinks and provenance, while providing more structured, opinionated visualisations and analysis.

Should I build “an MCP”?

It’s worth noting that this is not a mature protocol—it is continuously evolving. But the adoption has been fantastic—I opened the first random MCP aggregating website and it lists over 4000 servers coming from various organisations and individuals. I’d estimate there’s a lot more out there.

Building against MCP is a clear, well-defined thing to do, something that’s rare in the volatile landscape of AI. This could explain its popularity. But it doesn’t make a good product. It’s another tool in your toolbox.

I (and other folks at nilenso) maintain that good products are built on a foundation that requires software engineering maturity, and this is especially true of AI products.

So let’s revisit what MCP brings to the table:

This decoupling is not free of cost. There is extra scaffolding to make your applications talk this protocol. Your LLM performance is sensitive to prompting and tool descriptions. Adding lots of tools indiscriminately affects latencies and overall quality of your responses.

It makes sense for GitHub to expose repository actions for AI tools like Cursor or Windsurf to carry out. This is a valuable form of decoupling.

Does it make sense to have this decoupling for an internal tool, where the clients and servers are under your control, and the value comes from having well-optimised finetuned responses? Probably not.

Anywho, here’s some references. Happy building.

References, for a deeper dive

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

MCP协议 AI集成 CKAN 开放数据 工具调用
相关文章