fix tool count issue
This commit is contained in:
+11
-4
@@ -57,8 +57,8 @@ if CLERK_SECRET_KEY and CLERK_ISSUER:
|
|||||||
jwks_uri=f"{CLERK_ISSUER}/.well-known/jwks.json",
|
jwks_uri=f"{CLERK_ISSUER}/.well-known/jwks.json",
|
||||||
issuer=CLERK_ISSUER,
|
issuer=CLERK_ISSUER,
|
||||||
algorithm="RS256",
|
algorithm="RS256",
|
||||||
audience=CLERK_PUBLISHABLE_KEY, # Use publishable key as audience
|
audience=None, # Disable audience validation - Clerk uses different audience format
|
||||||
required_scopes=["yargi.read"] # Global scope requirement
|
required_scopes=[] # Disable scope validation - Clerk JWT has ['read', 'search']
|
||||||
)
|
)
|
||||||
logger.info(f"Bearer auth configured with Clerk JWKS: {CLERK_ISSUER}/.well-known/jwks.json")
|
logger.info(f"Bearer auth configured with Clerk JWKS: {CLERK_ISSUER}/.well-known/jwks.json")
|
||||||
else:
|
else:
|
||||||
@@ -165,8 +165,15 @@ async def health_check():
|
|||||||
"auth_enabled": os.getenv("ENABLE_AUTH", "false").lower() == "true"
|
"auth_enabled": os.getenv("ENABLE_AUTH", "false").lower() == "true"
|
||||||
})
|
})
|
||||||
|
|
||||||
# Mount MCP app at /mcp (not at root to avoid conflicts)
|
# Add explicit redirect for /mcp to /mcp/ with method preservation
|
||||||
app.mount("/mcp", mcp_app)
|
@app.api_route("/mcp", methods=["GET", "POST", "HEAD", "OPTIONS"])
|
||||||
|
async def redirect_to_slash(request: Request):
|
||||||
|
"""Redirect /mcp to /mcp/ preserving HTTP method with 308"""
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
return RedirectResponse(url="/mcp/", status_code=308)
|
||||||
|
|
||||||
|
# Mount MCP app at /mcp/ with trailing slash
|
||||||
|
app.mount("/mcp/", mcp_app)
|
||||||
|
|
||||||
# Set the lifespan context after mounting
|
# Set the lifespan context after mounting
|
||||||
app.router.lifespan_context = mcp_app.lifespan
|
app.router.lifespan_context = mcp_app.lifespan
|
||||||
|
|||||||
+19
-8
@@ -240,12 +240,25 @@ from fastmcp import FastMCP
|
|||||||
|
|
||||||
def create_app(auth=None):
|
def create_app(auth=None):
|
||||||
"""Create FastMCP app with standard capabilities and optional auth."""
|
"""Create FastMCP app with standard capabilities and optional auth."""
|
||||||
|
global app
|
||||||
if auth:
|
if auth:
|
||||||
app = FastMCP("Yargı MCP Server", auth=auth)
|
# Replace placeholder app with auth-enabled app, keeping all tools/resources
|
||||||
|
auth_app = FastMCP("Yargı MCP Server", auth=auth)
|
||||||
|
# Copy all tools and resources from placeholder app to auth-enabled app
|
||||||
|
auth_app._tool_manager = app._tool_manager
|
||||||
|
auth_app._resource_manager = app._resource_manager
|
||||||
|
app = auth_app
|
||||||
logger.info("MCP server created with Bearer authentication enabled")
|
logger.info("MCP server created with Bearer authentication enabled")
|
||||||
else:
|
else:
|
||||||
app = FastMCP("Yargı MCP Server")
|
# Update placeholder app name
|
||||||
|
app.name = "Yargı MCP Server"
|
||||||
logger.info("MCP server created with standard capabilities (FastMCP handles tools.listChanged automatically)")
|
logger.info("MCP server created with standard capabilities (FastMCP handles tools.listChanged automatically)")
|
||||||
|
|
||||||
|
# Add token counting middleware
|
||||||
|
token_counter = TokenCountingMiddleware()
|
||||||
|
app.add_middleware(token_counter)
|
||||||
|
logger.info("Token counting middleware added to MCP server")
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
# --- Module Imports ---
|
# --- Module Imports ---
|
||||||
@@ -335,13 +348,11 @@ from bddk_mcp_module.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Create app without auth initially (auth will be added in ASGI wrapper)
|
# Create a placeholder app that will be properly initialized after tools are defined
|
||||||
app = create_app()
|
from fastmcp import FastMCP
|
||||||
|
|
||||||
# --- Add Token Counting Middleware ---
|
# Placeholder app for decorators - will be replaced in create_app() after all tools are defined
|
||||||
token_counter = TokenCountingMiddleware()
|
app = FastMCP("Yargı MCP Server Placeholder")
|
||||||
app.add_middleware(token_counter)
|
|
||||||
logger.info("Token counting middleware added to MCP server")
|
|
||||||
|
|
||||||
# --- Tool Documentation Resources ---
|
# --- Tool Documentation Resources ---
|
||||||
@app.resource("docs://tools/yargitay")
|
@app.resource("docs://tools/yargitay")
|
||||||
|
|||||||
Reference in New Issue
Block a user