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
85 changes: 41 additions & 44 deletions mcpgateway/admin.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions mcpgateway/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,15 +1428,15 @@ def reject(self, admin_email: str, reason: str, notes: Optional[str] = None) ->
"server_resource_association",
Base.metadata,
Column("server_id", String(36), ForeignKey("servers.id"), primary_key=True),
Column("resource_id", Integer, ForeignKey("resources.id"), primary_key=True),
Column("resource_id", String(36), ForeignKey("resources.id"), primary_key=True),
)

# Association table for servers and prompts
server_prompt_association = Table(
"server_prompt_association",
Base.metadata,
Column("server_id", String(36), ForeignKey("servers.id"), primary_key=True),
Column("prompt_id", Integer, ForeignKey("prompts.id"), primary_key=True),
Column("prompt_id", String(36), ForeignKey("prompts.id"), primary_key=True),
)

# Association table for servers and A2A agents
Expand Down Expand Up @@ -1496,7 +1496,7 @@ class ResourceMetric(Base):

Attributes:
id (int): Primary key.
resource_id (int): Foreign key linking to the resource.
resource_id (str): Foreign key linking to the resource.
timestamp (datetime): The time when the invocation occurred.
response_time (float): The response time in seconds.
is_success (bool): True if the invocation succeeded, False otherwise.
Expand All @@ -1506,7 +1506,7 @@ class ResourceMetric(Base):
__tablename__ = "resource_metrics"

id: Mapped[int] = mapped_column(primary_key=True)
resource_id: Mapped[int] = mapped_column(Integer, ForeignKey("resources.id"), nullable=False)
resource_id: Mapped[str] = mapped_column(String(36), ForeignKey("resources.id"), nullable=False)
timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
response_time: Mapped[float] = mapped_column(Float, nullable=False)
is_success: Mapped[bool] = mapped_column(Boolean, nullable=False)
Expand Down Expand Up @@ -1548,7 +1548,7 @@ class PromptMetric(Base):

Attributes:
id (int): Primary key.
prompt_id (int): Foreign key linking to the prompt.
prompt_id (str): Foreign key linking to the prompt.
timestamp (datetime): The time when the invocation occurred.
response_time (float): The response time in seconds.
is_success (bool): True if the invocation succeeded, False otherwise.
Expand All @@ -1558,7 +1558,7 @@ class PromptMetric(Base):
__tablename__ = "prompt_metrics"

id: Mapped[int] = mapped_column(primary_key=True)
prompt_id: Mapped[int] = mapped_column(Integer, ForeignKey("prompts.id"), nullable=False)
prompt_id: Mapped[str] = mapped_column(String(36), ForeignKey("prompts.id"), nullable=False)
timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
response_time: Mapped[float] = mapped_column(Float, nullable=False)
is_success: Mapped[bool] = mapped_column(Boolean, nullable=False)
Expand Down Expand Up @@ -2210,7 +2210,7 @@ class Resource(Base):

__tablename__ = "resources"

id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: uuid.uuid4().hex)
uri: Mapped[str] = mapped_column(String(767), nullable=False)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
Expand All @@ -2219,7 +2219,8 @@ class Resource(Base):
uri_template: Mapped[Optional[str]] = mapped_column(Text, nullable=True) # URI template for parameterized resources
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, onupdate=utc_now)
is_active: Mapped[bool] = mapped_column(default=True)
# is_active: Mapped[bool] = mapped_column(default=True)
enabled: Mapped[bool] = mapped_column(default=True)
tags: Mapped[List[str]] = mapped_column(JSON, default=list, nullable=False)

# Comprehensive metadata for audit tracking
Expand Down Expand Up @@ -2423,7 +2424,7 @@ class ResourceSubscription(Base):
__tablename__ = "resource_subscriptions"

id: Mapped[int] = mapped_column(primary_key=True)
resource_id: Mapped[int] = mapped_column(ForeignKey("resources.id"))
resource_id: Mapped[str] = mapped_column(ForeignKey("resources.id"))
subscriber_id: Mapped[str] = mapped_column(String(255), nullable=False) # Client identifier
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
last_notification: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True)
Expand Down Expand Up @@ -2469,14 +2470,15 @@ class Prompt(Base):

__tablename__ = "prompts"

id: Mapped[int] = mapped_column(primary_key=True)
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: uuid.uuid4().hex)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
template: Mapped[str] = mapped_column(Text)
argument_schema: Mapped[Dict[str, Any]] = mapped_column(JSON)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, onupdate=utc_now)
is_active: Mapped[bool] = mapped_column(default=True)
# is_active: Mapped[bool] = mapped_column(default=True)
enabled: Mapped[bool] = mapped_column(default=True)
tags: Mapped[List[str]] = mapped_column(JSON, default=list, nullable=False)

# Comprehensive metadata for audit tracking
Expand Down Expand Up @@ -2667,7 +2669,8 @@ class Server(Base):
icon: Mapped[Optional[str]] = mapped_column(String(767), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now, onupdate=utc_now)
is_active: Mapped[bool] = mapped_column(default=True)
# is_active: Mapped[bool] = mapped_column(default=True)
enabled: Mapped[bool] = mapped_column(default=True)
tags: Mapped[List[str]] = mapped_column(JSON, default=list, nullable=False)

# Comprehensive metadata for audit tracking
Expand Down
8 changes: 4 additions & 4 deletions mcpgateway/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@ async def list_resource_templates(
Returns:
ListResourceTemplatesResult: A paginated list of resource templates.
"""
logger.debug(f"User {user} requested resource templates")
logger.info(f"User {user} requested resource templates")
resource_templates = await resource_service.list_resource_templates(db)
# For simplicity, we're not implementing real pagination here
return ListResourceTemplatesResult(_meta={}, resource_templates=resource_templates, next_cursor=None) # No pagination for now
Expand All @@ -2767,7 +2767,7 @@ async def list_resource_templates(
@resource_router.post("/{resource_id}/toggle")
@require_permission("resources.update")
async def toggle_resource_status(
resource_id: int,
resource_id: str,
activate: bool = True,
db: Session = Depends(get_db),
user=Depends(get_current_user_with_permissions),
Expand All @@ -2776,7 +2776,7 @@ async def toggle_resource_status(
Activate or deactivate a resource by its ID.

Args:
resource_id (int): The ID of the resource.
resource_id (str): The ID of the resource.
activate (bool): True to activate, False to deactivate.
db (Session): Database session.
user (str): Authenticated user.
Expand Down Expand Up @@ -3126,7 +3126,7 @@ async def subscribe_resource(user=Depends(get_current_user_with_permissions)) ->
@prompt_router.post("/{prompt_id}/toggle")
@require_permission("prompts.update")
async def toggle_prompt_status(
prompt_id: int,
prompt_id: str,
activate: bool = True,
db: Session = Depends(get_db),
user=Depends(get_current_user_with_permissions),
Expand Down
16 changes: 9 additions & 7 deletions mcpgateway/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ class ResourceRead(BaseModelWithConfigDict):
- Metrics: Aggregated metrics for the resource invocations.
"""

id: int
id: str = Field(description="Unique ID of the resource")
uri: str
name: str
description: Optional[str]
Expand All @@ -1780,7 +1780,7 @@ class ResourceRead(BaseModelWithConfigDict):
size: Optional[int]
created_at: datetime
updated_at: datetime
is_active: bool
enabled: bool
metrics: ResourceMetrics
tags: List[Dict[str, str]] = Field(default_factory=list, description="Tags for categorizing the resource")

Expand Down Expand Up @@ -2280,14 +2280,15 @@ class PromptRead(BaseModelWithConfigDict):
- Metrics: Aggregated metrics for the prompt invocations.
"""

id: int
id: str = Field(description="Unique ID of the prompt")
name: str
description: Optional[str]
template: str
arguments: List[PromptArgument]
created_at: datetime
updated_at: datetime
is_active: bool
# is_active: bool
enabled: bool
tags: List[Dict[str, str]] = Field(default_factory=list, description="Tags for categorizing the prompt")
metrics: PromptMetrics

Expand Down Expand Up @@ -3710,10 +3711,11 @@ class ServerRead(BaseModelWithConfigDict):
icon: Optional[str]
created_at: datetime
updated_at: datetime
is_active: bool
# is_active: bool
enabled: bool
associated_tools: List[str] = []
associated_resources: List[int] = []
associated_prompts: List[int] = []
associated_resources: List[str] = []
associated_prompts: List[str] = []
associated_a2a_agents: List[str] = []
metrics: ServerMetrics
tags: List[Dict[str, str]] = Field(default_factory=list, description="Tags for categorizing the server")
Expand Down
5 changes: 3 additions & 2 deletions mcpgateway/services/completion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ async def _complete_prompt_argument(self, db: Session, ref: Dict[str, Any], arg_
if not prompt_name:
raise CompletionError("Missing prompt name")

prompt = db.execute(select(DbPrompt).where(DbPrompt.name == prompt_name).where(DbPrompt.is_active)).scalar_one_or_none()
# Only consider prompts that are enabled (renamed from `is_active` -> `enabled`)
prompt = db.execute(select(DbPrompt).where(DbPrompt.name == prompt_name).where(DbPrompt.enabled)).scalar_one_or_none()

if not prompt:
raise CompletionError(f"Prompt not found: {prompt_name}")
Expand Down Expand Up @@ -265,7 +266,7 @@ async def _complete_resource_uri(self, db: Session, ref: Dict[str, Any], arg_val
raise CompletionError("Missing URI template")

# List matching resources
resources = db.execute(select(DbResource).where(DbResource.is_active)).scalars().all()
resources = db.execute(select(DbResource).where(DbResource.enabled)).scalars().all()

# Filter by URI pattern
matches = []
Expand Down
3 changes: 2 additions & 1 deletion mcpgateway/services/export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ async def _export_prompts(self, db: Session, tags: Optional[List[str]], include_
"description": prompt.description,
"input_schema": input_schema,
"tags": prompt.tags or [],
"is_active": prompt.is_active,
# Use the new `enabled` attribute on prompt objects but keep export key `is_active` for compatibility
"is_active": getattr(prompt, "enabled", getattr(prompt, "is_active", False)),
}

# Convert arguments to input schema format
Expand Down
Loading
Loading