Skip to content

Commit 64becf4

Browse files
authored
add mcpToken as an optional plugin configuration (#1671)
* add mcpToken as an optional plugin configuration Signed-off-by: Stephanie <yangcao@redhat.com> * update readme Signed-off-by: Stephanie <yangcao@redhat.com> * remove debug message Signed-off-by: Stephanie <yangcao@redhat.com> * update to include mcp server name as well Signed-off-by: Stephanie <yangcao@redhat.com> * update error message Signed-off-by: Stephanie <yangcao@redhat.com> * update referenced_documents Signed-off-by: Stephanie <yangcao@redhat.com> * update readme Signed-off-by: Stephanie <yangcao@redhat.com> --------- Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent 7c0fb0f commit 64becf4

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

workspaces/lightspeed/plugins/lightspeed-backend/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Add the following lightspeed configurations into your `app-config.yaml` file:
3333
lightspeed:
3434
servicePort: <portNumber> # Optional - Change the LS service port nubmer. Defaults to 8080.
3535
systemPrompt: <system prompt> # Optional - Override the default system prompt.
36+
mcpServers: # Optional - only one mcp server is currently supported
37+
- name: <mcp server name> # must match the name configured in LCS
38+
token: ${MCP_TOKEN}
3639
```
3740
3841
#### Permission Framework Support

workspaces/lightspeed/plugins/lightspeed-backend/config.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,21 @@ export interface Config {
3030
* @visibility backend
3131
*/
3232
systemPrompt?: string;
33+
/**
34+
* configure the MCP server for the lightspeed service.
35+
* @visibility backend
36+
*/
37+
mcpServers?: Array<{
38+
/**
39+
* The name of the mcp server.
40+
* @visibility backend
41+
*/
42+
name: string;
43+
/**
44+
* The access token for authenticating MCP server.
45+
* @visibility secret
46+
*/
47+
token: string;
48+
}>;
3349
};
3450
}

workspaces/lightspeed/plugins/lightspeed-backend/src/service/router.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export async function createRouter(
5151

5252
const port = config.getOptionalNumber('lightspeed.servicePort') ?? 8080;
5353
const system_prompt = config.getOptionalString('lightspeed.systemPrompt');
54+
// Only support one MCP server for now
55+
const mcpServerName = config
56+
.getOptionalConfigArray('lightspeed.mcpServers')?.[0]
57+
?.getString('name');
58+
const mcpToken = config
59+
.getOptionalConfigArray('lightspeed.mcpServers')?.[0]
60+
?.getString('token');
5461

5562
router.get('/health', (_, response) => {
5663
response.json({ status: 'ok' });
@@ -147,7 +154,7 @@ export async function createRouter(
147154
if (!fetchResponse.ok) {
148155
// Read the error body
149156
const errorBody = await fetchResponse.json();
150-
const errormsg = `Error from road-core server: ${errorBody.error?.message || errorBody?.detail?.cause || 'Unknown error'}`;
157+
const errormsg = `Error from lightspeed-core server: ${errorBody.error?.message || errorBody?.detail?.cause || 'Unknown error'}`;
151158
logger.error(errormsg);
152159

153160
// Return a 500 status for any upstream error
@@ -187,20 +194,23 @@ export async function createRouter(
187194
);
188195
const userQueryParam = `user_id=${encodeURIComponent(user_id)}`;
189196
request.body.media_type = 'application/json'; // set media_type to receive start and end event
190-
191197
// if system_prompt is defined in lightspeed config
192198
// set system_prompt to override the default rhdh system prompt
193199
if (system_prompt && system_prompt.trim().length > 0) {
194200
request.body.system_prompt = system_prompt;
195201
}
196202

197203
const requestBody = JSON.stringify(request.body);
204+
const mcpHeaders = mcpToken
205+
? `{"${mcpServerName}": {"Authorization": "Bearer ${mcpToken}"}}`
206+
: '';
198207
const fetchResponse = await fetch(
199208
`http://0.0.0.0:${port}/v1/streaming_query?${userQueryParam}`,
200209
{
201210
method: 'POST',
202211
headers: {
203212
'Content-Type': 'application/json',
213+
'MCP-HEADERS': mcpHeaders,
204214
},
205215
body: requestBody,
206216
},
@@ -209,7 +219,7 @@ export async function createRouter(
209219
if (!fetchResponse.ok) {
210220
// Read the error body
211221
const errorBody = await fetchResponse.json();
212-
const errormsg = `Error from road-core server: ${errorBody.error?.message || errorBody?.detail?.cause || 'Unknown error'}`;
222+
const errormsg = `Error from lightspeed-core server: ${errorBody.error?.message || errorBody?.detail?.cause || 'Unknown error'}`;
213223
logger.error(errormsg);
214224

215225
// Return a 500 status for any upstream error

workspaces/lightspeed/plugins/lightspeed/src/hooks/useConversationMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const useConversationMessages = (
138138
content: aiMessage.content,
139139
timestamp: aiMessage.timestamp,
140140
sources: transformDocumentsToSources(
141-
aiMessage?.referencedDocuments ?? [],
141+
aiMessage?.referenced_documents ?? [],
142142
),
143143
}),
144144
],

workspaces/lightspeed/plugins/lightspeed/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export interface LCSConversation {
5757
messages: BaseMessage[];
5858
started_at: string;
5959
completed_at: string;
60-
referencedDocuments?: ReferencedDocuments;
60+
referenced_documents?: ReferencedDocuments;
6161
}
6262

6363
export interface LCSShield {
@@ -75,7 +75,7 @@ export interface BaseMessage {
7575
model: string;
7676
timestamp: string;
7777
sources?: SourcesCardProps;
78-
referencedDocuments?: ReferencedDocuments;
78+
referenced_documents?: ReferencedDocuments;
7979
error?: AlertProps;
8080
}
8181
export type ConversationSummary = {

workspaces/lightspeed/plugins/lightspeed/src/utils/lightspeed-chatbox-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export const getConversationsData = (
167167
? new Date(conversation.completed_at).getTime()
168168
: Date.now(),
169169
),
170-
referencedDocuments: botMessage?.referencedDocuments ?? [],
170+
referenced_documents: botMessage?.referenced_documents ?? [],
171171
},
172172
];
173173
};

0 commit comments

Comments
 (0)