Skip to content

Commit f1e953d

Browse files
Michael Christensenim-michaelc
authored andcommitted
Add input data models
1 parent b33aefc commit f1e953d

File tree

1 file changed

+50
-0
lines changed
  • src/amazon-keyspaces-mcp-server/awslabs/amazon_keyspaces_mcp_server

1 file changed

+50
-0
lines changed

src/amazon-keyspaces-mcp-server/awslabs/amazon_keyspaces_mcp_server/models.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
# limitations under the License.
1414
"""Data models for Keyspaces MCP Server."""
1515

16+
import re
1617
from dataclasses import dataclass, field
1718
from typing import Any, Dict, List
1819

20+
from pydantic import BaseModel, Field, field_validator
21+
1922

2023
@dataclass
2124
class KeyspaceInfo:
@@ -126,3 +129,50 @@ class QueryAnalysisResult:
126129
is_full_table_scan: bool = False
127130
recommendations: List[str] = field(default_factory=list)
128131
performance_assessment: str = ''
132+
133+
134+
# Pydantic models for input validation
135+
class KeyspaceInput(BaseModel):
136+
"""Validated keyspace input."""
137+
keyspace: str = Field(
138+
...,
139+
min_length=1,
140+
max_length=48,
141+
pattern=r'^[a-zA-Z][a-zA-Z0-9_]*$',
142+
description='Keyspace name (alphanumeric and underscore only)'
143+
)
144+
145+
146+
class TableInput(BaseModel):
147+
"""Validated table input."""
148+
keyspace: str = Field(
149+
...,
150+
min_length=1,
151+
max_length=48,
152+
pattern=r'^[a-zA-Z][a-zA-Z0-9_]*$'
153+
)
154+
table: str = Field(
155+
...,
156+
min_length=1,
157+
max_length=48,
158+
pattern=r'^[a-zA-Z][a-zA-Z0-9_]*$'
159+
)
160+
161+
162+
class QueryInput(BaseModel):
163+
"""Validated query input."""
164+
keyspace: str = Field(
165+
...,
166+
min_length=1,
167+
max_length=48,
168+
pattern=r'^[a-zA-Z][a-zA-Z0-9_]*$'
169+
)
170+
query: str = Field(..., min_length=1, max_length=10000)
171+
172+
@field_validator('query')
173+
@classmethod
174+
def sanitize_query(cls, v: str) -> str:
175+
"""Strip hidden unicode and control characters."""
176+
v = re.sub(r'[\u200B-\u200D\uFEFF\u0000-\u001F\u007F-\u009F]', '', v)
177+
return v.strip()
178+

0 commit comments

Comments
 (0)