当前位置: 首页 > news >正文

mcp sse 直接调用mcp方法

haris-musa/excel-mcp-server | DeepWiki

from mcp import ClientSession  
from mcp.client.sse import sse_client  
import asyncio  async def connect_to_mcp_sse():  """通过 SSE 连接到 MCP 服务器"""  url = "http://localhost:8017/sse"  async with sse_client(url) as (read, write):  async with ClientSession(read, write) as session:  # 初始化连接  await session.initialize()  print("已连接到 MCP 服务器")  # 列出所有可用工具  tools = await session.list_tools()  print("\n可用工具:")  for tool in tools.tools:  print(f"- {tool.name}: {tool.description}")  # 调用工具示例  result = await session.call_tool(  "create_workbook",  arguments={"filepath": "test.xlsx"}  )  print(f"\n工具调用结果: {result}")  # 读取数据示例  result = await session.call_tool(  "read_data_from_excel",  arguments={  "filepath": "test.xlsx",  "sheet_name": "Sheet1",  "start_cell": "A1",  "preview_only": True  }  )  print(f"\n读取数据结果: {result}")  # 运行客户端  
asyncio.run(connect_to_mcp_sse())
已连接到 MCP 服务器可用工具:
- apply_formula:Apply Excel formula to cell.Excel formula will write to cell with verification.- validate_formula_syntax: Validate Excel formula syntax without applying it.
- format_range: Apply formatting to a range of cells.
- read_data_from_excel:Read data from Excel worksheet with cell metadata including validation rules.Args:filepath: Path to Excel filesheet_name: Name of worksheetstart_cell: Starting cell (default A1)end_cell: Ending cell (optional, auto-expands if not provided)preview_only: Whether to return preview onlyReturns:JSON string containing structured cell data with validation metadata.Each cell includes: address, value, row, column, and validation info (if any).- write_data_to_excel:Write data to Excel worksheet.Excel formula will write to cell without any verification.PARAMETERS:filepath: Path to Excel filesheet_name: Name of worksheet to write todata: List of lists containing data to write to the worksheet, sublists are assumed to be
rowsstart_cell: Cell to start writing to, default is "A1"- create_workbook: Create new Excel workbook.
- create_worksheet: Create new worksheet in workbook.
- create_chart: Create chart in worksheet.
- create_pivot_table: Create pivot table in worksheet.
- create_table: Creates a native Excel table from a specified range of data.
- copy_worksheet: Copy worksheet within workbook.
- delete_worksheet: Delete worksheet from workbook.
- rename_worksheet: Rename worksheet in workbook.
- get_workbook_metadata: Get metadata about workbook including sheets, ranges, etc.
- merge_cells: Merge a range of cells.
- unmerge_cells: Unmerge a range of cells.
- get_merged_cells: Get merged cells in a worksheet.
- copy_range: Copy a range of cells to another location.
- delete_range: Delete a range of cells and shift remaining cells.
- validate_excel_range: Validate if a range exists and is properly formatted.
- get_data_validation_info:Get all data validation rules in a worksheet.This tool helps identify which cell ranges have validation rulesand what types of validation are applied.Args:filepath: Path to Excel filesheet_name: Name of worksheetReturns:JSON string containing all validation rules in the worksheet- insert_rows: Insert one or more rows starting at the specified row.
- insert_columns: Insert one or more columns starting at the specified column.
- delete_sheet_rows: Delete one or more rows starting at the specified row.
- delete_sheet_columns: Delete one or more columns starting at the specified column.工具调用结果: meta=None content=[TextContent(type='text', text='Created workbook at ./excel_fi
les\\test.xlsx', annotations=None, meta=None)] structuredContent={'result': 'Created workbook
at ./excel_files\\test.xlsx'} isError=False读取数据结果: meta=None content=[TextContent(type='text', text='{\n  "range": "A1:A1",\n  "she
et_name": "Sheet1",\n  "cells": [\n    {\n      "address": "A1",\n      "value": null,\n
"row": 1,\n      "column": 1,\n      "validation": {\n        "has_validation": false\n      }
\n    }\n  ]\n}', annotations=None, meta=None)] structuredContent={'result': '{\n  "range": "A
1:A1",\n  "sheet_name": "Sheet1",\n  "cells": [\n    {\n      "address": "A1",\n      "value":null,\n      "row": 1,\n      "column": 1,\n  

http://www.dtcms.com/a/450444.html

相关文章:

  • 11、Linux 密码管理
  • dedecms网站地图路径修改生成后 网站地图前台路径不变爬虫怎么看网站开发者模式
  • 思科交换机VLAN超简单配置(草稿)
  • 上海兼职网站制作seo网站优化外包
  • lol视频网站模板网站开发公司安心加盟
  • 期货网站开发杭州工程建设网
  • 8. 直线方程式
  • 小红书网站开发费用电脑做服务器上传网站
  • 丘受网站谁做的网球吧电商是做什么
  • daya87—字符串—同构字符串(LeetCode-205)
  • AI编程开发系统018-基于Vue+SpringBoot的付费自习室管理系统(源码+部署说明+演示视频+源码介绍+lw)
  • 网站建设合同前期需注意哪些问题海口财务
  • 写网站的教程宝安专业网站建设
  • 黑龙江营商环境建设局网站呼和浩特市做网站公司好的
  • Redis核心通用命令深度解析
  • 官方网站的推广策划怎么做企业查询宝下载
  • python如何控制电脑鼠标
  • 网站建设记录过程wordpress中接入支付宝
  • 一个网站的预算吉林省住房与建设厅网站
  • 网站动态小图标网站建设的流程步骤
  • 网站你懂我意思正能量晚上下载绵竹seo
  • 简约式网站模板怎样用dw做网站
  • SNN论文阅读——Apprenticeship-Inspired Elegance
  • 楚雄市住房和城乡建设局门户网站2345网址导航12年11个
  • 宣城 网站建设汽车宣传软文
  • leetcode 567. 字符串的排列
  • 抚顺地区网站建设儒枫网网站建设
  • 网站seo优化技能网站 建设网站
  • WordPress多页切换菜单南山网站优化
  • 手写MyBatis第94弹:调试追踪MyBatis SQL执行流程的终极指南