Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bme-mcp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何家明
bme-mcp
Commits
70188e1a
Commit
70188e1a
authored
Oct 21, 2025
by
何家明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加能环碳e管家的接口
parent
e7d4538d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
148 additions
and
20 deletions
+148
-20
README.md
README.md
+50
-1
client.py
client/client.py
+21
-17
config.yaml
config/config.yaml
+1
-1
server.py
server/server.py
+76
-1
No files found.
README.md
View file @
70188e1a
...
...
@@ -2,6 +2,18 @@
初次使用,请执行以下命令初始化mcp环境
请提前下载:https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/
下载并运行安装程序,勾选以下组件(关键):
“Desktop development with C++”(桌面开发 C++ 套件)
确保勾选子选项中的 “MSVC v143 生成工具”(或更高版本,对应 VS 2022)和 “Windows 11 SDK”(或对应系统版本的 SDK)。
也可以去 https://pypi.org/project/asyncmy/#files 下载文件名类似 asyncmy-0.2.10-cp312-cp312-win_amd64.whl 的包,这里的312对应你的python版本
然后执行 pip install asyncmy-0.2.10-cp312-cp312-win_amd64.whl -i https://mirrors.aliyun.com/pypi/simple/
```
uv init bme-mcp
...
...
@@ -38,4 +50,41 @@ model:
api_key
:
Tc7sY47hiU5d1LNGbJjGBfqfY13IE3khIc0uBvpJ11U
base_url
:
http://10.10.10.12:30100/v1
model_name
:
deepseek-v3
```
\ No newline at end of file
```
## 部署
### 路径
conda activate mcp_jiaming
cd /home/data2/mcp_jiaming/bme-mcp
### 启动
python3 api.py
### 缺包
pip install xxx
如果下载慢,可以pip install xxx -i https://mirrors.aliyun.com/pypi/simple/
### 运行
nohup python3 api.py &> log/root.log &
### 停止
windows: tasklist | findstr /i "py"
linux: ps -ef | grep py
找到api.py和./server/server.py,两个进程都要关闭
### 其他
#### 查看某模块版本
windows: pip list | findstr xxx
linux: pip list | grep xxx
client/client.py
View file @
70188e1a
import
asyncio
import
json
import
traceback
from
datetime
import
datetime
from
typing
import
Optional
...
...
@@ -64,23 +65,26 @@ class McpClient:
)
async
def
_session_keepalive
(
self
):
logger
.
info
(
"Start to get stdio client..."
)
async
with
stdio_client
(
self
.
server_params
)
as
client
:
logger
.
info
(
"Start to get stdio client session..."
)
async
with
ClientSession
(
*
client
)
as
session
:
logger
.
info
(
"Start to initialize stdio client session..."
)
await
session
.
initialize
()
logger
.
info
(
"End to initialize stdio client session..."
)
self
.
session
=
session
await
self
.
read_mcp
()
logger
.
info
(
"Loop to keep session alive..."
)
try
:
while
True
:
await
asyncio
.
sleep
(
10
)
await
session
.
send_ping
()
except
Exception
as
e
:
logger
.
exception
(
e
)
self
.
session
=
None
try
:
logger
.
info
(
"Start to get stdio client..."
)
async
with
stdio_client
(
self
.
server_params
)
as
client
:
logger
.
info
(
"Start to get stdio client session..."
)
async
with
ClientSession
(
*
client
)
as
session
:
logger
.
info
(
"Start to initialize stdio client session..."
)
await
session
.
initialize
()
logger
.
info
(
"End to initialize stdio client session..."
)
self
.
session
=
session
await
self
.
read_mcp
()
logger
.
info
(
"Loop to keep session alive..."
)
try
:
while
True
:
await
asyncio
.
sleep
(
10
)
await
session
.
send_ping
()
except
Exception
as
e
:
logger
.
exception
(
e
)
self
.
session
=
None
except
Exception
as
e
:
logger
.
error
(
f
"Unexpected error: {str(e)}
\n
完整异常栈:
\n
{traceback.format_exc()}"
)
async
def
start
(
self
):
asyncio
.
create_task
(
self
.
_session_keepalive
())
...
...
config/config.yaml
View file @
70188e1a
...
...
@@ -42,7 +42,7 @@ remote:
base_url
:
bme-screen-service
:
https://vis.bmetech.com/vis
# bme-screen-service: http://localhost:9070/screen
bme-
pc-service
:
https://vis.bmetech.com/vispc
bme-
reduce-cost-screen-service
:
https://vis.bmetech.com/reducecostscreen
# 跨域配置
cors
:
...
...
server/server.py
View file @
70188e1a
import
os
import
sys
from
typing
import
List
,
Any
from
typing
import
Any
import
requests
from
mcp.server.fastmcp
import
FastMCP
...
...
@@ -18,6 +18,8 @@ base_url = remote["base_url"]
bme_screen_service
=
base_url
[
"bme-screen-service"
]
bme_reduce_cost_screen_service
=
base_url
[
"bme-reduce-cost-screen-service"
]
def
deal_request_exception
(
response
):
"""
...
...
@@ -245,6 +247,79 @@ def get_stopped_dust_collector(customer_id: int) -> Any:
}
for
record
in
response_data
]
return
result
@
mcp
.
tool
()
def
get_emission_inventory
(
customer_id
:
int
)
->
Any
:
"""
根据客户id获取无组织排放清单
:param customer_id: 客户id
:return: 返回结构中的字段名解释:
count: 类型数量
name: 排放源类型
"""
response
=
requests
.
get
(
bme_reduce_cost_screen_service
+
"/homePage/getEmissionInventory"
,
{
"customerId"
:
customer_id
},
headers
=
headers
)
response_data
=
deal_request_exception
(
response
)
.
get
(
"data"
,
{})
.
get
(
"typeCount"
,
[])
result
=
[{
"count"
:
record
.
get
(
"count"
),
"name"
:
record
.
get
(
"name"
)
}
for
record
in
response_data
]
return
result
@
mcp
.
tool
()
def
get_video_monitor
(
customer_id
:
int
)
->
Any
:
"""
根据客户id获取视频监控情况
:param customer_id: 客户id
:return: 返回结构中的字段名解释:
online: 在线监控数量
offline: 离线监控数量
"""
response
=
requests
.
get
(
bme_reduce_cost_screen_service
+
"/homePage/video/monitor"
,
{
"customerId"
:
customer_id
},
headers
=
headers
)
return
deal_request_exception
(
response
)
.
get
(
"data"
,
{})
.
get
(
"data"
,
{})
@
mcp
.
tool
()
def
get_today_transaction_statistics
(
customer_id
:
int
)
->
Any
:
"""
根据客户id获取今日闭环统计
:param customer_id: 客户id
:return: 返回结构中的字段名解释:
totalCount: 今日闭环数量
finishedCount: 今日已处理数量
hourCount: 小时闭环数量
"""
response
=
requests
.
get
(
bme_reduce_cost_screen_service
+
"/homePage/transaction/doc/getTodayTransactionStatistics"
,
{
"customerId"
:
customer_id
},
headers
=
headers
)
return
deal_request_exception
(
response
)
.
get
(
"data"
,
{})
@
mcp
.
tool
()
def
get_wash_car_summary
(
customer_id
:
int
)
->
Any
:
"""
根据客户id获取清洁调度信息
:param customer_id: 客户id
:return: 返回结构中的字段名解释:
carWasherCount: 洗车机数量(台)
dayCount: 今日洗车(次)
weekCount: 本周洗车(次)
cleaningCountTotal: 清洁车数量(台)
scheduleCountTotal: 今日调度(次)
distanceTotal: 今日清扫里程(米)
"""
response1
=
requests
.
get
(
bme_reduce_cost_screen_service
+
"/homePage/findCarWashCount"
,
{
"customerId"
:
customer_id
},
headers
=
headers
)
response1_data
=
deal_request_exception
(
response1
)
.
get
(
"data"
,
{})
response2
=
requests
.
get
(
bme_reduce_cost_screen_service
+
"/homePage/product/cleaner/summary"
,
{
"customerId"
:
customer_id
},
headers
=
headers
)
response2_data
=
deal_request_exception
(
response2
)
.
get
(
"data"
,
{})
return
response1_data
|
response2_data
@
mcp
.
resource
(
"api://customers"
)
def
get_all_available_customer
()
->
Any
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment