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
fb872812
Commit
fb872812
authored
May 12, 2025
by
何家明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整会话保持逻辑
parent
5c1cb255
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
17 deletions
+8
-17
client.py
client/client.py
+8
-17
No files found.
client/client.py
View file @
fb872812
...
@@ -27,7 +27,6 @@ class McpClient:
...
@@ -27,7 +27,6 @@ class McpClient:
self
.
default_system_prompt
=
None
# mcp_server提供的默认提示词
self
.
default_system_prompt
=
None
# mcp_server提供的默认提示词
self
.
available_tools
:
[]
=
None
# mcp_server提供的tool
self
.
available_tools
:
[]
=
None
# mcp_server提供的tool
self
.
session
:
Optional
[
ClientSession
]
=
None
self
.
session
:
Optional
[
ClientSession
]
=
None
# self.exit_stack = AsyncExitStack()
active_model
=
config
[
"model"
][
config
[
"active"
]]
active_model
=
config
[
"model"
][
config
[
"active"
]]
self
.
client
=
AsyncOpenAI
(
self
.
client
=
AsyncOpenAI
(
api_key
=
active_model
[
"api_key"
],
api_key
=
active_model
[
"api_key"
],
...
@@ -39,33 +38,26 @@ class McpClient:
...
@@ -39,33 +38,26 @@ class McpClient:
args
=
config
[
"server"
][
"args"
],
args
=
config
[
"server"
][
"args"
],
)
)
async
def
_session_
ping
(
self
):
async
def
_session_
keepalive
(
self
):
logger
.
info
(
f
"Start to get stdio client..."
)
logger
.
info
(
"Start to get stdio client..."
)
async
with
stdio_client
(
self
.
server_params
)
as
client
:
async
with
stdio_client
(
self
.
server_params
)
as
client
:
logger
.
info
(
f
"Start to get stdio client session..."
)
logger
.
info
(
"Start to get stdio client session..."
)
async
with
ClientSession
(
*
client
)
as
session
:
async
with
ClientSession
(
*
client
)
as
session
:
logger
.
info
(
f
"Start to initialize stdio client session..."
)
logger
.
info
(
"Start to initialize stdio client session..."
)
await
session
.
initialize
()
await
session
.
initialize
()
logger
.
info
(
f
"End to initialize stdio client session..."
)
logger
.
info
(
"End to initialize stdio client session..."
)
self
.
session
=
session
self
.
session
=
session
await
self
.
read_mcp
()
try
:
try
:
while
True
:
while
True
:
logger
.
info
(
f
"Start to ping stdio client session..."
)
logger
.
info
(
"Start to ping stdio client session..."
)
await
asyncio
.
sleep
(
10
)
await
asyncio
.
sleep
(
10
)
await
session
.
send_ping
()
await
session
.
send_ping
()
logger
.
info
(
f
"End to ping stdio client session..."
)
logger
.
info
(
"End to ping stdio client session..."
)
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
exception
(
e
)
logger
.
exception
(
e
)
self
.
session
=
None
self
.
session
=
None
async
def
_session_keepalive
(
self
):
while
True
:
try
:
logger
.
info
(
f
"Start to keep session alive..."
)
await
self
.
_session_ping
()
except
Exception
as
e
:
logger
.
exception
(
e
)
async
def
start
(
self
):
async
def
start
(
self
):
asyncio
.
create_task
(
self
.
_session_keepalive
())
asyncio
.
create_task
(
self
.
_session_keepalive
())
...
@@ -207,7 +199,6 @@ async def lifespan(app):
...
@@ -207,7 +199,6 @@ async def lifespan(app):
async
def
user_query
(
message
:
str
,
customer_id
:
str
):
async
def
user_query
(
message
:
str
,
customer_id
:
str
):
try
:
try
:
await
instance
.
read_mcp
()
async
for
r
in
instance
.
process_query
(
message
,
customer_id
):
async
for
r
in
instance
.
process_query
(
message
,
customer_id
):
yield
r
yield
r
except
Exception
as
e
:
except
Exception
as
e
:
...
...
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