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
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai-websearch-mcp"
version = "0.4.0"
version = "0.4.1"
description = "using openai websearch as mcp server"
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -10,12 +10,14 @@ dependencies = [
"mcp==1.3.0",
"tzdata==2025.1",
"openai==1.66.2",
"typer==0.15.2"
"typer==0.15.2",
"httmcp==0.1.4",
]


[project.scripts]
openai-websearch-mcp = "openai_websearch_mcp:main"
openai-websearch-mcp-runner = "openai_websearch_mcp:runner"
openai-websearch-mcp-install = "openai_websearch_mcp.cli:app"


Expand All @@ -30,5 +32,6 @@ dev-dependencies = [
"mcp==1.3.0",
"tzdata==2025.1",
"openai==1.66.2",
"typer==0.15.2"
"typer==0.15.2",
"httmcp==0.1.4",
]
58 changes: 58 additions & 0 deletions src/openai_websearch_mcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,63 @@ def main():
mcp.run()


def runner():
import sys, json, traceback
from starlette.testclient import TestClient
from fastapi import FastAPI
app = FastAPI()
app.include_router(mcp.router)

try:
# create a test client
client = TestClient(app)

print("MCP Server started, waiting for requests from stdin...", file=sys.stderr)

# Handle requests until EOF
while True:
try:
line = sys.stdin.readline()
if not line: # EOF
break

# Check if the input is valid JSON
try:
request_data = json.loads(line)
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON input: {str(e)}", file=sys.stderr)
continue

print(f"Received request: {request_data}", file=sys.stderr)
# Construct the path
jsonrpc_method = request_data.get("method")
path = f"mcp/{mcp.name}/{jsonrpc_method}"

# Send the request to the ASGI application
try:
response = client.post(path, json=request_data)
response_data = response.json()

# Send the response back to the client
print(json.dumps(response_data, ensure_ascii=False))
sys.stdout.flush()
except Exception as e:
# Send the error message to stderr
print(f"Error processing request: {str(e)}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
sys.stderr.flush()

except Exception as e:
# Send the error message to stderr
print(f"Unexpected error: {str(e)}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
sys.stderr.flush()
except Exception as e:
# Startup error
print(f"Startup error: {str(e)}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
sys.exit(1)


if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions src/openai_websearch_mcp/__main__.py

This file was deleted.

6 changes: 3 additions & 3 deletions src/openai_websearch_mcp/server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pydantic import BaseModel
from typing import Literal
from mcp.server.fastmcp import FastMCP
from httmcp import HTTMCP
from openai import OpenAI
from pydantic_extra_types.timezone_name import TimeZoneName
from pydantic import BaseModel

mcp = FastMCP(
name="OpenAI Web Search",
mcp = HTTMCP(
name="openai_web_search",
instructions="This MCP server provides access to OpenAI's websearch functionality through the Model Context Protocol."
)

Expand Down
102 changes: 101 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.