mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix: Add type annotations for improved type safety in various modules
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
NextFunction,
|
||||
ExpressJson,
|
||||
} from "Common/Server/Utils/Express";
|
||||
import { getMCPServer } from "../Server/MCPServer";
|
||||
import { getMCPServer, McpServer } from "../Server/MCPServer";
|
||||
import SessionManager, { SessionData } from "../Server/SessionManager";
|
||||
import { McpToolInfo } from "../Types/McpTypes";
|
||||
import {
|
||||
@@ -163,7 +163,7 @@ async function handleNewSession(
|
||||
res: ExpressResponse,
|
||||
apiKey: string,
|
||||
): Promise<void> {
|
||||
const mcpServer = getMCPServer();
|
||||
const mcpServer: McpServer = getMCPServer();
|
||||
|
||||
const transport: StreamableHTTPServerTransport =
|
||||
new StreamableHTTPServerTransport({
|
||||
|
||||
@@ -72,7 +72,7 @@ export default class OneUptimeApiService {
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await this.makeApiRequest(
|
||||
const response: JSONValue = await this.makeApiRequest(
|
||||
operation,
|
||||
route,
|
||||
headers,
|
||||
@@ -206,7 +206,14 @@ export default class OneUptimeApiService {
|
||||
|
||||
private static buildCreateData(args: OneUptimeToolCallArgs): JSONObject {
|
||||
const createData: JSONObject = {};
|
||||
const reservedFields = ["id", "query", "select", "skip", "limit", "sort"];
|
||||
const reservedFields: string[] = [
|
||||
"id",
|
||||
"query",
|
||||
"select",
|
||||
"skip",
|
||||
"limit",
|
||||
"sort",
|
||||
];
|
||||
|
||||
for (const [key, value] of Object.entries(args)) {
|
||||
if (!reservedFields.includes(key)) {
|
||||
@@ -219,7 +226,14 @@ export default class OneUptimeApiService {
|
||||
|
||||
private static buildUpdateData(args: OneUptimeToolCallArgs): JSONObject {
|
||||
const updateData: JSONObject = {};
|
||||
const reservedFields = ["id", "query", "select", "skip", "limit", "sort"];
|
||||
const reservedFields: string[] = [
|
||||
"id",
|
||||
"query",
|
||||
"select",
|
||||
"skip",
|
||||
"limit",
|
||||
"sort",
|
||||
];
|
||||
|
||||
for (const [key, value] of Object.entries(args)) {
|
||||
if (!reservedFields.includes(key)) {
|
||||
@@ -308,13 +322,22 @@ export default class OneUptimeApiService {
|
||||
operation: OneUptimeOperation,
|
||||
args: OneUptimeToolCallArgs,
|
||||
): void {
|
||||
const reservedFields = ["id", "query", "select", "skip", "limit", "sort"];
|
||||
const reservedFields: string[] = [
|
||||
"id",
|
||||
"query",
|
||||
"select",
|
||||
"skip",
|
||||
"limit",
|
||||
"sort",
|
||||
];
|
||||
|
||||
switch (operation) {
|
||||
case OneUptimeOperation.Create: {
|
||||
const createDataFields = Object.keys(args).filter((key: string) => {
|
||||
return !reservedFields.includes(key);
|
||||
});
|
||||
const createDataFields: string[] = Object.keys(args).filter(
|
||||
(key: string) => {
|
||||
return !reservedFields.includes(key);
|
||||
},
|
||||
);
|
||||
if (createDataFields.length === 0) {
|
||||
throw new Error(
|
||||
"At least one data field is required for create operation",
|
||||
@@ -332,9 +355,11 @@ export default class OneUptimeApiService {
|
||||
if (!args.id) {
|
||||
throw new Error(`ID is required for ${operation} operation`);
|
||||
}
|
||||
const updateDataFields = Object.keys(args).filter((key: string) => {
|
||||
return !reservedFields.includes(key);
|
||||
});
|
||||
const updateDataFields: string[] = Object.keys(args).filter(
|
||||
(key: string) => {
|
||||
return !reservedFields.includes(key);
|
||||
},
|
||||
);
|
||||
if (updateDataFields.length === 0) {
|
||||
throw new Error(
|
||||
"At least one data field is required for update operation",
|
||||
|
||||
@@ -56,7 +56,10 @@ export function generateAllFieldsSelect(
|
||||
);
|
||||
|
||||
try {
|
||||
const ModelClass = findModelClass(tableName, modelType);
|
||||
const ModelClass:
|
||||
| ModelConstructor<BaseModel>
|
||||
| ModelConstructor<AnalyticsBaseModel>
|
||||
| null = findModelClass(tableName, modelType);
|
||||
|
||||
if (!ModelClass) {
|
||||
MCPLogger.warn(
|
||||
|
||||
@@ -112,7 +112,7 @@ export function generateToolsForDatabaseModel(
|
||||
const pluralName: string = model.pluralName || `${singularName}s`;
|
||||
const apiPath: string | undefined = model.crudApiPath?.toString();
|
||||
|
||||
const modelInfo = {
|
||||
const modelInfo: ModelToolsResult["modelInfo"] = {
|
||||
tableName: modelName,
|
||||
singularName,
|
||||
pluralName,
|
||||
@@ -182,7 +182,7 @@ export function generateToolsForAnalyticsModel(
|
||||
const pluralName: string = model.pluralName || `${singularName}s`;
|
||||
const apiPath: string | undefined = model.crudApiPath?.toString();
|
||||
|
||||
const modelInfo = {
|
||||
const modelInfo: ModelToolsResult["modelInfo"] = {
|
||||
tableName: modelName,
|
||||
singularName,
|
||||
pluralName,
|
||||
|
||||
@@ -58,7 +58,10 @@ describe("OneUptime MCP Server", () => {
|
||||
// Mock the service to throw error for missing API key
|
||||
(OneUptimeApiService.initialize as jest.Mock).mockImplementation(
|
||||
(config: unknown) => {
|
||||
const typedConfig = config as { url: string; apiKey: string };
|
||||
const typedConfig: { url: string; apiKey: string } = config as {
|
||||
url: string;
|
||||
apiKey: string;
|
||||
};
|
||||
if (!typedConfig.apiKey) {
|
||||
throw new Error("OneUptime API key is required");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user