Compare commits
No commits in common. "f34a737d0c6d4bcfe941b65b5d83b4a5bc03fb8e" and "3d6c45f2b4a35b2c8e3d3ea6325a48271ca350c0" have entirely different histories.
f34a737d0c
...
3d6c45f2b4
|
@ -2,7 +2,6 @@ from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
import uvicorn
|
|
||||||
|
|
||||||
from . import tools
|
from . import tools
|
||||||
|
|
||||||
|
@ -27,22 +26,7 @@ app.add_middleware(
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def setup_mcp():
|
for tool in tools.get_tools():
|
||||||
try:
|
|
||||||
from fastapi_mcp import FastApiMCP
|
|
||||||
mcp = FastApiMCP(app)
|
|
||||||
mcp.mount()
|
|
||||||
print('MCP mounted')
|
|
||||||
except ImportError:
|
|
||||||
print('MCP could not be mounted')
|
|
||||||
|
|
||||||
def setup_tools():
|
|
||||||
for tool in tools.get_tools():
|
|
||||||
component, method = tool.__name__.split('.')
|
component, method = tool.__name__.split('.')
|
||||||
path = f'/{component}/{method}'
|
path = f'/{component}/{method}'
|
||||||
app.get(path, response_model=None,tags=[component])(tool)
|
app.get(path, response_model=None,tags=[component])(tool)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
setup_tools()
|
|
||||||
setup_mcp()
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
||||||
|
|
|
@ -60,11 +60,10 @@ RETURN_FORMATS = {
|
||||||
|
|
||||||
RETURN_FORMAT = 'json'
|
RETURN_FORMAT = 'json'
|
||||||
|
|
||||||
|
MAX_TOOL_RESULT_LEN = 1000
|
||||||
APPEND_RESULT_TYPE_DOCS = True
|
APPEND_RESULT_TYPE_DOCS = True
|
||||||
|
|
||||||
def wrap_method(class_, method, max_tool_result_len = 1_000_000_000,
|
def wrap_method(class_, method):
|
||||||
provide_instructions: bool = False):
|
|
||||||
logger.info('Wrapping %s.%s', class_.__name__, method.__name__)
|
logger.info('Wrapping %s.%s', class_.__name__, method.__name__)
|
||||||
return_type = method.__annotations__.get('return', '')
|
return_type = method.__annotations__.get('return', '')
|
||||||
is_iterator = str(return_type).startswith(
|
is_iterator = str(return_type).startswith(
|
||||||
|
@ -92,13 +91,10 @@ def wrap_method(class_, method, max_tool_result_len = 1_000_000_000,
|
||||||
repr(input_value),
|
repr(input_value),
|
||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
if len(result_str) > max_tool_result_len:
|
if len(result_str) > MAX_TOOL_RESULT_LEN:
|
||||||
result_str = result_str[:max_tool_result_len]
|
result_str = result_str[:MAX_TOOL_RESULT_LEN] + ' (remaining tool result elicited...)'
|
||||||
if provide_instructions:
|
|
||||||
result_str += '\nremaining tool result elicited...'
|
|
||||||
if provide_instructions:
|
|
||||||
if APPEND_RESULT_TYPE_DOCS and (return_docs := getattr(return_type, '__doc__', None)):
|
if APPEND_RESULT_TYPE_DOCS and (return_docs := getattr(return_type, '__doc__', None)):
|
||||||
result_str += '\n'+return_docs
|
result_str = result_str+'\n'+return_docs
|
||||||
return result_str
|
return result_str
|
||||||
|
|
||||||
wrapper.__name__ = f'{class_.__name__}.{method.__name__}'
|
wrapper.__name__ = f'{class_.__name__}.{method.__name__}'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user