use native connector types for MCP OAuth, restore original UI

This commit is contained in:
CREDO23 2026-04-22 08:57:28 +02:00
parent 940889c291
commit ea3508cb25
5 changed files with 34 additions and 89 deletions

View file

@ -530,11 +530,12 @@ async def load_mcp_tools(
return list(cached_tools)
try:
# Find all connectors with MCP server config: generic MCP_CONNECTOR type
# and service-specific types (LINEAR_CONNECTOR, etc.) created via MCP OAuth.
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.connector_type
== SearchSourceConnectorType.MCP_CONNECTOR,
SearchSourceConnector.search_space_id == search_space_id,
SearchSourceConnector.config.has_key("server_config"), # noqa: W601
),
)

View file

@ -56,9 +56,7 @@ def _get_token_encryption() -> TokenEncryption:
def _build_redirect_uri(service: str) -> str:
base = config.BACKEND_URL
if not base:
raise HTTPException(status_code=500, detail="BACKEND_URL not configured.")
base = config.BACKEND_URL or "http://localhost:8000"
return f"{base.rstrip('/')}/api/v1/auth/mcp/{service}/connector/callback"
@ -288,6 +286,7 @@ async def mcp_oauth_callback(
}
# ---- Re-auth path ----
db_connector_type = SearchSourceConnectorType(svc.connector_type)
reauth_connector_id = data.get("connector_id")
if reauth_connector_id:
result = await session.execute(
@ -295,8 +294,7 @@ async def mcp_oauth_callback(
SearchSourceConnector.id == reauth_connector_id,
SearchSourceConnector.user_id == user_id,
SearchSourceConnector.search_space_id == space_id,
SearchSourceConnector.connector_type
== SearchSourceConnectorType.MCP_CONNECTOR,
SearchSourceConnector.connector_type == db_connector_type,
)
)
db_connector = result.scalars().first()
@ -329,15 +327,15 @@ async def mcp_oauth_callback(
# ---- New connector path ----
connector_name = await generate_unique_connector_name(
session,
SearchSourceConnectorType.MCP_CONNECTOR,
db_connector_type,
space_id,
user_id,
f"{svc.name} MCP",
svc.name,
)
new_connector = SearchSourceConnector(
name=connector_name,
connector_type=SearchSourceConnectorType.MCP_CONNECTOR,
connector_type=db_connector_type,
is_indexable=False,
config=connector_config,
search_space_id=space_id,
@ -388,26 +386,26 @@ async def reauth_mcp_service(
user: User = Depends(current_active_user),
session: AsyncSession = Depends(get_async_session),
):
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.id == connector_id,
SearchSourceConnector.user_id == user.id,
SearchSourceConnector.search_space_id == space_id,
SearchSourceConnector.connector_type
== SearchSourceConnectorType.MCP_CONNECTOR,
)
)
if not result.scalars().first():
raise HTTPException(
status_code=404, detail="MCP connector not found or access denied",
)
from app.services.mcp_oauth.registry import get_service
svc = get_service(service)
if not svc:
raise HTTPException(status_code=404, detail=f"Unknown MCP service: {service}")
db_connector_type = SearchSourceConnectorType(svc.connector_type)
result = await session.execute(
select(SearchSourceConnector).filter(
SearchSourceConnector.id == connector_id,
SearchSourceConnector.user_id == user.id,
SearchSourceConnector.search_space_id == space_id,
SearchSourceConnector.connector_type == db_connector_type,
)
)
if not result.scalars().first():
raise HTTPException(
status_code=404, detail="Connector not found or access denied",
)
try:
from app.services.mcp_oauth.discovery import (
discover_oauth_metadata,

View file

@ -15,6 +15,7 @@ from dataclasses import dataclass, field
class MCPServiceConfig:
name: str
mcp_url: str
connector_type: str
supports_dcr: bool = True
oauth_discovery_origin: str | None = None
client_id_env: str | None = None
@ -26,18 +27,22 @@ MCP_SERVICES: dict[str, MCPServiceConfig] = {
"linear": MCPServiceConfig(
name="Linear",
mcp_url="https://mcp.linear.app/mcp",
connector_type="LINEAR_CONNECTOR",
),
"jira": MCPServiceConfig(
name="Jira",
mcp_url="https://mcp.atlassian.com/v1/mcp",
connector_type="JIRA_CONNECTOR",
),
"clickup": MCPServiceConfig(
name="ClickUp",
mcp_url="https://mcp.clickup.com/mcp",
connector_type="CLICKUP_CONNECTOR",
),
"slack": MCPServiceConfig(
name="Slack",
mcp_url="https://mcp.slack.com/mcp",
connector_type="SLACK_CONNECTOR",
supports_dcr=False,
client_id_env="SLACK_CLIENT_ID",
client_secret_env="SLACK_CLIENT_SECRET",
@ -45,6 +50,7 @@ MCP_SERVICES: dict[str, MCPServiceConfig] = {
"airtable": MCPServiceConfig(
name="Airtable",
mcp_url="https://mcp.airtable.com/mcp",
connector_type="AIRTABLE_CONNECTOR",
oauth_discovery_origin="https://airtable.com",
),
}