Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python-mcp-client/source-code-final/mcp_client/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mcp import ClientSession
from openai import OpenAI

MODEL = "gpt-4o-mini"
MODEL = "gpt-5.4-mini"
MAX_TOKENS = 1000


Expand All @@ -25,7 +25,7 @@ async def process_query(self, query: str) -> str:
messages = [{"role": "user", "content": query}]
initial_response = self.openai.chat.completions.create(
model=MODEL,
max_tokens=MAX_TOKENS,
max_completion_tokens=MAX_TOKENS,
messages=messages,
tools=await self._get_tools(),
)
Expand Down Expand Up @@ -55,7 +55,7 @@ async def process_query(self, query: str) -> str:
# Get final Model's response after tool execution
final_response = self.openai.chat.completions.create(
model=MODEL,
max_tokens=MAX_TOKENS,
max_completion_tokens=MAX_TOKENS,
messages=messages,
)

Expand All @@ -75,7 +75,7 @@ async def _get_tools(self) -> list:
"description": tool.description or "No description",
"parameters": getattr(
tool,
"inputSchema",
"input_schema",
{"type": "object", "properties": {}},
),
},
Expand Down
11 changes: 5 additions & 6 deletions python-mcp-client/source-code-final/mcp_client/mcp_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from contextlib import AsyncExitStack
from typing import Any, Awaitable, Callable, ClassVar, Self
Expand Down Expand Up @@ -36,13 +37,11 @@ async def _connect_to_server(self) -> ClientSession:
read, write = await self.exit_stack.enter_async_context(
stdio_client(
server=StdioServerParameters(
command="sh",
args=[
"-c",
f"{sys.executable} {self.server_path} 2>/dev/null",
],
command=sys.executable,
args=[self.server_path],
env=None,
)
),
errlog=open(os.devnull, "w"),
)
)
client_session = await self.exit_stack.enter_async_context(
Expand Down
6 changes: 3 additions & 3 deletions python-mcp-client/source-code-final/mcp_server/mcp_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from mcp.server.fastmcp import FastMCP
from mcp.server.mcpserver import MCPServer

mcp = FastMCP("mcp_server")
mcp = MCPServer("mcp_server")


@mcp.tool()
Expand All @@ -12,7 +12,7 @@ async def echo(message: str) -> str:
@mcp.prompt()
async def greeting_prompt(name: str) -> str:
"""A simple greeting prompt."""
return f"Great {name} kindly."
return f"Greet {name} kindly."


@mcp.resource("file://./greeting.txt")
Expand Down
4 changes: 2 additions & 2 deletions python-mcp-client/source-code-final/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ description = "MCP client for testing MCP servers."
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"mcp>=1.20.0",
"openai>=2.6.1",
"mcp>=2.2.0,<3.0",
"openai>=3.16.2,<4.0",
]

[project.scripts]
Expand Down
Loading
Loading