Skip to content

Commit 24db721

Browse files
authored
Merge branch 'main' into bundle-mariadb
2 parents f83a4b6 + 0cc49ff commit 24db721

File tree

58 files changed

+7169
-3181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7169
-3181
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Open bug reports](https://img.shields.io/github/issues/y-scope/clp/bug?label=bugs)](https://github.com/y-scope/clp/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
44
[![Open feature requests](https://img.shields.io/github/issues/y-scope/clp/enhancement?label=feature-requests)](https://github.com/y-scope/clp/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
55
[![Discord][badge-discord]][yscope-community-discord]
6+
[![Slack][badge-slack]][yscope-community-slack]
67
[![CLP on Zulip][badge-zulip]][yscope-community-zulip]
78

89
YScope's Compressed Log Processor (CLP) compresses your logs, and allows you to search the
@@ -89,14 +90,16 @@ You can use GitHub issues to [report a bug][bug-report] or [request a feature][f
8990
Need help? Join us on one of our community servers:
9091

9192
* [![Discord][badge-discord]][yscope-community-discord]
93+
* [![Slack][badge-slack]][yscope-community-slack]
9294
* [![CLP on Zulip][badge-zulip]][yscope-community-zulip]
9395

9496
# Next Steps
9597

9698
This is our open-source release which we will be constantly updating with bug fixes, features, etc.
9799
If you would like a feature or want to report a bug, please file an issue and we'll be happy to engage.
98100

99-
[badge-discord]: https://img.shields.io/discord/1377353873068392580?style=flat&logo=discord&logoColor=white&label=Discord&labelColor=%235561f5
101+
[badge-discord]: https://img.shields.io/discord/1377353873068392580?style=flat&logo=discord&logoColor=white&label=Discord&labelColor=5561f5
102+
[badge-slack]: https://img.shields.io/badge/Slack-yscope--community-1e724f?style=flat&logo=slack&logoColor=white&labelColor=4A154B
100103
[badge-zulip]: https://img.shields.io/badge/Zulip-yscope--clp-1888FA?logo=zulip
101104
[bug-report]: https://github.com/y-scope/clp/issues/new?assignees=&labels=bug&template=bug-report.yml
102105
[build-package]: http://docs.yscope.com/clp/main/dev-docs/building-package
@@ -118,4 +121,5 @@ If you would like a feature or want to report a bug, please file an issue and we
118121
[re2]: https://github.com/google/re2
119122
[uber-blog]: https://www.uber.com/en-US/blog/reducing-logging-cost-by-two-orders-of-magnitude-using-clp
120123
[yscope-community-discord]: https://discord.gg/7kZA2m5G87
124+
[yscope-community-slack]: https://communityinviter.com/apps/yscopecommunity/yscope-community
121125
[yscope-community-zulip]: https://yscope-clp.zulipchat.com

components/clp-mcp-server/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ For more details on Claude Desktop MCP setup, see the
4949

5050
> **Warning:** 🚧 This section is still under construction.
5151
52+
## Testing
53+
54+
Use the following command to run all unit tests:
55+
56+
```shell
57+
uv test pytest
58+
```
59+
5260
[claude-desktop]: https://claude.ai/download
5361
[claude-desktop-mcp-doc]: https://modelcontextprotocol.io/docs/develop/connect-local-servers
5462
[mcp]: https://modelcontextprotocol.io/docs/getting-started/intro
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Constants for CLP MCP server."""
2+
3+
EXPIRED_SESSION_SWEEP_INTERVAL_SECONDS = 600 # 10 minutes
4+
NUM_ITEMS_PER_PAGE = 10
5+
MAX_CACHED_RESULTS = 1000
6+
# 10 minutes
7+
SESSION_TTL_SECONDS = 600
8+
9+
SERVER_NAME = "clp-mcp-server"
10+
11+
# fmt: off
12+
SYSTEM_PROMPT = (
13+
"You are an AI assistant that helps users query a log database using KQL (Kibana Query Language)."
14+
" You should generate a KQL query that accurately expresses the user's intent. The generated KQL"
15+
" query should be as specific as possible to minimize the number of log messages returned.\n\n"
16+
"You should consider the following guidelines to generate KQL queries efficiently:\n"
17+
"- Use specific field names and values to narrow down the search.\n"
18+
"- Avoid using wildcards (`*`) unless absolutely necessary, as they can lead to large result"
19+
" sets.\n"
20+
"- Use logical operators (`AND`, `OR`, `NOT`) to combine one or more key-value searches.\n"
21+
"- Consider the time range of the logs you are searching. If the user specifies a time range,"
22+
" include it in the KQL query.\n"
23+
"- If the user query is ambiguous or lacks detail, ask clarifying questions to better understand"
24+
" their intent before generating the KQL query.\n"
25+
"- Always ensure that the generated KQL query is syntactically correct and can be executed without"
26+
" errors."
27+
)
28+
# fmt: on

components/clp-mcp-server/clp_mcp_server/server/server.py

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,10 @@
22

33
from typing import Any
44

5-
from fastmcp import FastMCP
5+
from fastmcp import Context, FastMCP
66

7-
8-
class ProtocolConstant:
9-
"""Constants for the CLP MCP Server."""
10-
11-
SERVER_NAME = "clp-mcp-server"
12-
13-
# Tool names
14-
TOOL_HELLO_WORLD = "hello_world"
15-
TOOL_GET_SERVER_INFO = "get_server_info"
16-
17-
@classmethod
18-
def get_capabilities(cls) -> list[str]:
19-
"""
20-
Gets the capabilities of the server.
21-
:return: A list of tool names supported by the server.
22-
"""
23-
return [cls.TOOL_HELLO_WORLD, cls.TOOL_GET_SERVER_INFO]
7+
from . import constants
8+
from .session_manager import SessionManager
249

2510

2611
def create_mcp_server() -> FastMCP:
@@ -31,22 +16,44 @@ def create_mcp_server() -> FastMCP:
3116
:raise: Propagates `FastMCP.__init__`'s exceptions.
3217
:raise: Propagates `FastMCP.tool`'s exceptions.
3318
"""
34-
mcp = FastMCP(name=ProtocolConstant.SERVER_NAME)
19+
mcp = FastMCP(name=constants.SERVER_NAME)
20+
21+
session_manager = SessionManager(session_ttl_seconds=constants.SESSION_TTL_SECONDS)
3522

36-
@mcp.tool()
37-
def get_server_info() -> dict[str, Any]:
23+
@mcp.tool
24+
async def get_instructions(ctx: Context) -> str:
3825
"""
39-
Gets the MCP server's information.
26+
Gets a pre-defined "system prompt" that guides the LLM behavior.
27+
This function must be invoked before any other `FastMCP.tool`.
4028
41-
:return: The server's information with a list of capabilities.
29+
:param ctx: The `FastMCP` context containing the metadata of the underlying MCP session.
30+
:return: A string of "system prompt".
4231
"""
43-
return {
44-
"name": ProtocolConstant.SERVER_NAME,
45-
"capabilities": ProtocolConstant.get_capabilities(),
46-
"status": "running",
47-
}
32+
await session_manager.start()
33+
return session_manager.get_or_create_session(ctx.session_id).get_instructions()
34+
35+
@mcp.tool
36+
async def get_nth_page(page_index: int, ctx: Context) -> dict[str, Any]:
37+
"""
38+
Retrieves the n-th page of a paginated response with the paging metadata from the previous
39+
query.
40+
41+
:param page_index: Zero-based index, e.g., 0 for the first page.
42+
:param ctx: The `FastMCP` context containing the metadata of the underlying MCP session.
43+
:return: A dictionary containing the following key-value pairs on success:
44+
- "items": A list of log entries in the requested page.
45+
- "num_total_pages": Total number of pages available from the query as an integer.
46+
- "num_total_items": Total number of log entries available from the query as an integer.
47+
- "num_items_per_page": Number of log entries per page.
48+
- "has_next": Whether a page exists after the returned one.
49+
- "has_previous": Whether a page exists before the returned one.
50+
:return: A dictionary with the following key-value pair on failures:
51+
- "Error": An error message describing the failure.
52+
"""
53+
await session_manager.start()
54+
return session_manager.get_nth_page(ctx.session_id, page_index)
4855

49-
@mcp.tool()
56+
@mcp.tool
5057
def hello_world(name: str = "clp-mcp-server user") -> dict[str, Any]:
5158
"""
5259
Provides a simple hello world greeting.
@@ -56,7 +63,7 @@ def hello_world(name: str = "clp-mcp-server user") -> dict[str, Any]:
5663
"""
5764
return {
5865
"message": f"Hello World, {name.strip()}!",
59-
"server": ProtocolConstant.SERVER_NAME,
66+
"server": constants.SERVER_NAME,
6067
"status": "running",
6168
}
6269

0 commit comments

Comments
 (0)