-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
1174 lines (1010 loc) · 44.6 KB
/
types.go
File metadata and controls
1174 lines (1010 loc) · 44.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package contextforge
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"sync"
"time"
)
// Timestamp represents a time that can be unmarshalled from the ContextForge API.
// The API returns timestamps without timezone information, so we need custom parsing.
type Timestamp struct {
time.Time
}
// UnmarshalJSON implements json.Unmarshaler for Timestamp.
func (t *Timestamp) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
if s == "" {
return nil
}
// Try parsing with timezone first (RFC3339)
parsed, err := time.Parse(time.RFC3339, s)
if err == nil {
t.Time = parsed
return nil
}
// Try parsing without timezone (ContextForge format)
parsed, err = time.Parse("2006-01-02T15:04:05.999999", s)
if err == nil {
t.Time = parsed
return nil
}
// Try parsing without microseconds
parsed, err = time.Parse("2006-01-02T15:04:05", s)
if err != nil {
return err
}
t.Time = parsed
return nil
}
// MarshalJSON implements json.Marshaler for Timestamp.
func (t Timestamp) MarshalJSON() ([]byte, error) {
if t.Time.IsZero() {
return []byte("null"), nil
}
return json.Marshal(t.Time.Format(time.RFC3339))
}
// FlexibleID represents an ID that can be either a string or integer from the API.
// The ContextForge API inconsistently returns IDs as integers in some responses (e.g., CREATE)
// and as strings in others (e.g., GET). This type handles both cases.
type FlexibleID string
// UnmarshalJSON handles both string and integer ID values from the API.
func (f *FlexibleID) UnmarshalJSON(data []byte) error {
// Try to unmarshal as string first
var s string
if err := json.Unmarshal(data, &s); err == nil {
*f = FlexibleID(s)
return nil
}
// If that fails, try as integer
var i int
if err := json.Unmarshal(data, &i); err == nil {
*f = FlexibleID(fmt.Sprintf("%d", i))
return nil
}
return fmt.Errorf("id must be string or integer")
}
// String returns the string representation of the ID.
func (f FlexibleID) String() string {
return string(f)
}
// Client manages communication with the ContextForge MCP Gateway API.
type Client struct {
clientMu sync.Mutex // protects the client during calls
client *http.Client // HTTP client used to communicate with the API
// Address for API requests.
// Defaults to http://localhost:8000/, but can be
// overridden to point to another ContextForge instance.
Address *url.URL
// User agent used when communicating with the ContextForge API.
UserAgent string
// Bearer token (JWT) for API authentication
BearerToken string
common service // Reuse a single struct instead of allocating one for each service
// Services used for talking to different parts of the ContextForge API
Tools *ToolsService
Resources *ResourcesService
Gateways *GatewaysService
Servers *ServersService
Prompts *PromptsService
Agents *AgentsService
Teams *TeamsService
Cancel *CancellationService
// Rate limit tracking
rateMu sync.Mutex
rateLimits map[string]Rate
}
// service provides a general service interface for the API.
type service struct {
client *Client
}
// ToolsService handles communication with the tool related
// methods of the ContextForge API.
type ToolsService service
// ResourcesService handles communication with the resource related
// methods of the ContextForge API.
type ResourcesService service
// GatewaysService handles communication with the gateway related
// methods of the ContextForge API.
type GatewaysService service
// ServersService handles communication with the server related
// methods of the ContextForge API.
type ServersService service
// PromptsService handles communication with the prompt related
// methods of the ContextForge API.
type PromptsService service
// AgentsService handles communication with the A2A agent related
// methods of the ContextForge API.
type AgentsService service
// TeamsService handles communication with the team related
// methods of the ContextForge API.
type TeamsService service
// CancellationService handles communication with the cancellation related
// methods of the ContextForge API.
type CancellationService service
// Response wraps the standard http.Response and provides convenient access to
// pagination and rate limit information.
type Response struct {
*http.Response
// Pagination cursor extracted from response
NextCursor string
// Rate limiting information
Rate Rate
}
// Rate represents the rate limit information returned in API responses.
type Rate struct {
// The maximum number of requests that can be made in the current window.
Limit int
// The number of requests remaining in the current window.
Remaining int
// The time at which the current rate limit window resets.
Reset time.Time
}
// ListOptions specifies the optional parameters to various List methods that
// support pagination.
type ListOptions struct {
// Limit specifies the maximum number of items to return.
// The API may return fewer than this value.
Limit int `url:"limit,omitempty"`
// Cursor is an opaque string used for pagination.
// To get the next page of results, pass the NextCursor from the
// previous response.
Cursor string `url:"cursor,omitempty"`
// IncludePagination requests body-based pagination metadata in API responses.
// When true, list endpoints return an object with items and nextCursor fields.
IncludePagination bool `url:"include_pagination,omitempty"`
}
// Tag represents a tag that can be unmarshaled from either a string or an object.
// In v1.0.0+, the API returns tags as objects with id and label fields,
// but accepts simple strings as input. This type handles both formats.
//
// Example input (create/update): ["tag1", "tag2"]
// Example output (read): [{"id":"tag1","label":"tag1"}, {"id":"tag2","label":"tag2"}]
type Tag struct {
ID string `json:"id"`
Label string `json:"label"`
}
// String returns the tag name (ID).
func (t Tag) String() string {
return t.ID
}
// UnmarshalJSON handles both string and object formats for tags.
// This allows seamless parsing of both old string format and new object format.
func (t *Tag) UnmarshalJSON(data []byte) error {
// Try to unmarshal as string first
var s string
if err := json.Unmarshal(data, &s); err == nil {
t.ID = s
t.Label = s
return nil
}
// Fall back to object format
type tagAlias Tag // prevent recursion
var obj tagAlias
if err := json.Unmarshal(data, &obj); err != nil {
return err
}
*t = Tag(obj)
return nil
}
// MarshalJSON outputs tags as strings for API input compatibility.
func (t Tag) MarshalJSON() ([]byte, error) {
return json.Marshal(t.ID)
}
// NewTag creates a new Tag from a string.
func NewTag(name string) Tag {
return Tag{ID: name, Label: name}
}
// NewTags creates a slice of Tags from a slice of strings.
func NewTags(names []string) []Tag {
if names == nil {
return nil
}
tags := make([]Tag, len(names))
for i, name := range names {
tags[i] = NewTag(name)
}
return tags
}
// TagNames returns the tag names (IDs) from a slice of Tag objects.
// This is a convenience method for getting just the tag names.
func TagNames(tags []Tag) []string {
if tags == nil {
return nil
}
names := make([]string, len(tags))
for i, t := range tags {
names[i] = t.ID
}
return names
}
// Tool represents a ContextForge tool.
type Tool struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
Enabled bool `json:"enabled,omitempty"`
TeamID *string `json:"teamId,omitempty"`
Visibility string `json:"visibility,omitempty"`
Tags []Tag `json:"tags,omitempty"`
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
// Additional fields added in v1.0.0
Team *string `json:"team,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
}
// ToolListOptions specifies the optional parameters to the
// ToolsService.List method.
type ToolListOptions struct {
ListOptions
// IncludeInactive includes inactive tools in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
// Tags filters tools by tags (comma-separated)
Tags string `url:"tags,omitempty"`
// TeamID filters tools by team ID
TeamID string `url:"team_id,omitempty"`
// Visibility filters tools by visibility (public, private, etc.)
Visibility string `url:"visibility,omitempty"`
}
// ToolCreateOptions specifies additional options for creating a tool.
// These fields are placed at the top level of the request wrapper.
type ToolCreateOptions struct {
TeamID *string
Visibility *string
}
// Resource represents a ContextForge resource (read response).
type Resource struct {
// Core fields
ID *FlexibleID `json:"id,omitempty"`
URI string `json:"uri"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
MimeType *string `json:"mimeType,omitempty"`
Size *int `json:"size,omitempty"`
IsActive bool `json:"isActive"`
Enabled bool `json:"enabled,omitempty"`
Metrics *ResourceMetrics `json:"metrics,omitempty"`
// Organizational fields
Tags []Tag `json:"tags,omitempty"`
TeamID *string `json:"teamId,omitempty"`
Team *string `json:"team,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// Timestamps
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
}
// ResourceMetrics represents performance statistics for a resource.
type ResourceMetrics struct {
TotalExecutions int `json:"totalExecutions,omitempty"`
SuccessfulExecutions int `json:"successfulExecutions,omitempty"`
FailedExecutions int `json:"failedExecutions,omitempty"`
FailureRate float64 `json:"failureRate,omitempty"`
MinResponseTime *float64 `json:"minResponseTime,omitempty"`
MaxResponseTime *float64 `json:"maxResponseTime,omitempty"`
AvgResponseTime *float64 `json:"avgResponseTime,omitempty"`
LastExecutionTime *Timestamp `json:"lastExecutionTime,omitempty"`
}
// ResourceCreate represents the request body for creating a resource.
// Note: Uses snake_case field names as required by the API.
type ResourceCreate struct {
// Required fields
URI string `json:"uri"`
Name string `json:"name"`
Content any `json:"content"` // Can be string or binary data
// Optional fields (snake_case per API spec)
Description *string `json:"description,omitempty"`
MimeType *string `json:"mime_type,omitempty"`
Template *string `json:"template,omitempty"`
Tags []string `json:"tags,omitempty"`
}
// ResourceUpdate represents the request body for updating a resource.
//
// All fields are optional. The SDK uses a three-state semantics pattern:
// - nil pointer/slice: field will not be updated (omitted from request)
// - pointer to zero value or empty slice: field will be cleared/set to empty
// - pointer to value or populated slice: field will be set to that value
//
// Examples:
// - Don't update tags: Tags = nil
// - Clear all tags: Tags = []string{}
// - Set specific tags: Tags = []string{"tag1", "tag2"}
//
// Note: Uses camelCase field names as required by the API.
type ResourceUpdate struct {
// All fields optional (camelCase per API spec)
URI *string `json:"uri,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
MimeType *string `json:"mimeType,omitempty"`
Template *string `json:"template,omitempty"`
Content any `json:"content,omitempty"` // Can be string or binary data
Tags []string `json:"tags,omitempty"`
}
// ResourceCreateOptions specifies additional options for creating a resource.
// These fields are placed at the top level of the request wrapper.
type ResourceCreateOptions struct {
TeamID *string
Visibility *string
}
// ResourceListOptions specifies the optional parameters to the
// ResourcesService.List method.
type ResourceListOptions struct {
ListOptions
// IncludeInactive includes inactive resources in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
// Tags filters resources by tags (comma-separated)
Tags string `url:"tags,omitempty"`
// TeamID filters resources by team ID
TeamID string `url:"team_id,omitempty"`
// Visibility filters resources by visibility (public, private, etc.)
Visibility string `url:"visibility,omitempty"`
}
// ListResourceTemplatesResult represents the response from listing resource templates.
type ListResourceTemplatesResult struct {
Templates []ResourceTemplate `json:"templates"`
}
// ResourceTemplate represents a template for creating resources.
type ResourceTemplate struct {
Name string `json:"name"`
Description string `json:"description"`
URI string `json:"uri"`
MimeType string `json:"mime_type"`
}
// Gateway represents a ContextForge gateway.
type Gateway struct {
// Core fields
ID *string `json:"id,omitempty"`
Name string `json:"name"`
URL string `json:"url"`
Description *string `json:"description,omitempty"`
Transport string `json:"transport,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Reachable bool `json:"reachable,omitempty"`
Capabilities map[string]any `json:"capabilities,omitempty"`
// Authentication fields
PassthroughHeaders []string `json:"passthroughHeaders,omitempty"`
AuthType *string `json:"authType,omitempty"`
AuthUsername *string `json:"authUsername,omitempty"`
AuthPassword *string `json:"authPassword,omitempty"`
AuthToken *string `json:"authToken,omitempty"`
AuthHeaderKey *string `json:"authHeaderKey,omitempty"`
AuthHeaderValue *string `json:"authHeaderValue,omitempty"`
AuthHeaders []map[string]string `json:"authHeaders,omitempty"`
AuthValue *string `json:"authValue,omitempty"`
OAuthConfig map[string]any `json:"oauthConfig,omitempty"`
AuthQueryParamKey *string `json:"authQueryParamKey,omitempty"`
AuthQueryParamValue *string `json:"authQueryParamValue,omitempty"`
AuthQueryParamValueMasked *string `json:"authQueryParamValueMasked,omitempty"`
// Organizational fields
Tags []Tag `json:"tags,omitempty"`
TeamID *string `json:"teamId,omitempty"`
Team *string `json:"team,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// Timestamps
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
LastSeen *Timestamp `json:"lastSeen,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
Slug *string `json:"slug,omitempty"`
RefreshIntervalSeconds *int `json:"refreshIntervalSeconds,omitempty"`
LastRefreshAt *Timestamp `json:"lastRefreshAt,omitempty"`
}
// GatewayListOptions specifies the optional parameters to the
// GatewaysService.List method.
type GatewayListOptions struct {
ListOptions
// IncludeInactive includes inactive gateways in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
}
// GatewayCreateOptions specifies additional options for creating a gateway.
// These fields are placed at the top level of the request wrapper.
type GatewayCreateOptions struct {
TeamID *string
Visibility *string
}
// Server represents a ContextForge server (read response).
type Server struct {
// Core fields
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Icon *string `json:"icon,omitempty"`
IsActive bool `json:"isActive,omitempty"`
Enabled bool `json:"enabled,omitempty"`
Metrics *ServerMetrics `json:"metrics,omitempty"`
// Association fields
AssociatedTools []string `json:"associatedTools,omitempty"`
AssociatedResources []string `json:"associatedResources,omitempty"`
AssociatedPrompts []string `json:"associatedPrompts,omitempty"`
AssociatedA2aAgents []string `json:"associatedA2aAgents,omitempty"`
// Organizational fields
Tags []Tag `json:"tags,omitempty"`
TeamID *string `json:"teamId,omitempty"`
Team *string `json:"team,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// Timestamps
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
OAuthEnabled bool `json:"oauthEnabled,omitempty"`
OAuthConfig map[string]any `json:"oauthConfig,omitempty"`
}
// ServerMetrics represents performance statistics for a server.
type ServerMetrics struct {
TotalExecutions int `json:"totalExecutions"`
SuccessfulExecutions int `json:"successfulExecutions"`
FailedExecutions int `json:"failedExecutions"`
FailureRate float64 `json:"failureRate"`
MinResponseTime *float64 `json:"minResponseTime,omitempty"`
MaxResponseTime *float64 `json:"maxResponseTime,omitempty"`
AvgResponseTime *float64 `json:"avgResponseTime,omitempty"`
LastExecutionTime *Timestamp `json:"lastExecutionTime,omitempty"`
}
// ServerCreate represents the request body for creating a server.
// Note: Uses snake_case field names as required by the API.
type ServerCreate struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Icon *string `json:"icon,omitempty"`
Tags []string `json:"tags,omitempty"`
// Association fields (snake_case per API spec)
AssociatedTools []string `json:"associated_tools,omitempty"`
AssociatedResources []string `json:"associated_resources,omitempty"`
AssociatedPrompts []string `json:"associated_prompts,omitempty"`
AssociatedA2aAgents []string `json:"associated_a2a_agents,omitempty"`
// Organizational fields (snake_case per API spec)
TeamID *string `json:"team_id,omitempty"`
OwnerEmail *string `json:"owner_email,omitempty"`
Visibility *string `json:"visibility,omitempty"`
}
// ServerUpdate represents the request body for updating a server.
//
// All fields are optional. The SDK uses a three-state semantics pattern:
// - nil pointer/slice: field will not be updated (omitted from request)
// - pointer to zero value or empty slice: field will be cleared/set to empty
// - pointer to value or populated slice: field will be set to that value
//
// Note: Uses camelCase field names as required by the API.
type ServerUpdate struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Icon *string `json:"icon,omitempty"`
Tags []string `json:"tags,omitempty"`
// Association fields (camelCase per API spec)
AssociatedTools []string `json:"associatedTools,omitempty"`
AssociatedResources []string `json:"associatedResources,omitempty"`
AssociatedPrompts []string `json:"associatedPrompts,omitempty"`
AssociatedA2aAgents []string `json:"associatedA2aAgents,omitempty"`
// Organizational fields (camelCase per API spec)
TeamID *string `json:"teamId,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
}
// ServerListOptions specifies the optional parameters to the
// ServersService.List method.
type ServerListOptions struct {
ListOptions
// IncludeInactive includes inactive servers in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
// Tags filters servers by tags (comma-separated)
Tags string `url:"tags,omitempty"`
// TeamID filters servers by team ID
TeamID string `url:"team_id,omitempty"`
// Visibility filters servers by visibility (public, private, etc.)
Visibility string `url:"visibility,omitempty"`
}
// ServerCreateOptions specifies additional options for creating a server.
// These fields are placed at the top level of the request wrapper.
type ServerCreateOptions struct {
TeamID *string
Visibility *string
}
// ServerAssociationOptions specifies the optional parameters for listing
// server associations (tools, resources, prompts).
type ServerAssociationOptions struct {
// IncludeInactive includes inactive items in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
}
// Prompt represents a ContextForge prompt (read response).
// Note: These types are shared between ServersService and the future PromptsService.
type Prompt struct {
// Core fields
// Note: ID changed from int to string in v1.0.0
ID string `json:"id"`
Name string `json:"name"`
OriginalName *string `json:"originalName,omitempty"`
CustomName *string `json:"customName,omitempty"`
CustomNameSlug *string `json:"customNameSlug,omitempty"`
DisplayName *string `json:"displayName,omitempty"`
GatewaySlug *string `json:"gatewaySlug,omitempty"`
Description *string `json:"description,omitempty"`
Template string `json:"template"`
Arguments []PromptArgument `json:"arguments"`
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
IsActive bool `json:"isActive"`
Enabled bool `json:"enabled,omitempty"` // v1.0.0 uses 'enabled' in addition to 'isActive'
Tags []Tag `json:"tags,omitempty"`
Metrics *PromptMetrics `json:"metrics,omitempty"`
// Organizational fields
TeamID *string `json:"teamId,omitempty"`
Team *string `json:"team,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
}
// PromptArgument represents a parameter definition for a prompt.
type PromptArgument struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
// PromptMetrics represents performance statistics for a prompt.
type PromptMetrics struct {
TotalExecutions int `json:"totalExecutions"`
SuccessfulExecutions int `json:"successfulExecutions"`
FailedExecutions int `json:"failedExecutions"`
FailureRate float64 `json:"failureRate"`
MinResponseTime *float64 `json:"minResponseTime,omitempty"`
MaxResponseTime *float64 `json:"maxResponseTime,omitempty"`
AvgResponseTime *float64 `json:"avgResponseTime,omitempty"`
LastExecutionTime *Timestamp `json:"lastExecutionTime,omitempty"`
}
// PromptCreate represents the request body for creating a prompt.
// Note: Uses snake_case field names as required by the API.
type PromptCreate struct {
Name string `json:"name"`
CustomName *string `json:"custom_name,omitempty"`
DisplayName *string `json:"display_name,omitempty"`
Description *string `json:"description,omitempty"`
Template string `json:"template"`
Arguments []PromptArgument `json:"arguments,omitempty"`
Tags []string `json:"tags,omitempty"`
// Organizational fields (snake_case per API spec)
TeamID *string `json:"team_id,omitempty"`
OwnerEmail *string `json:"owner_email,omitempty"`
Visibility *string `json:"visibility,omitempty"`
}
// PromptUpdate represents the request body for updating a prompt.
//
// All fields are optional. The SDK uses a three-state semantics pattern:
// - nil pointer/slice: field will not be updated (omitted from request)
// - pointer to zero value or empty slice: field will be cleared/set to empty
// - pointer to value or populated slice: field will be set to that value
//
// Note: Uses camelCase field names as required by the API.
type PromptUpdate struct {
Name *string `json:"name,omitempty"`
CustomName *string `json:"customName,omitempty"`
DisplayName *string `json:"displayName,omitempty"`
Description *string `json:"description,omitempty"`
Template *string `json:"template,omitempty"`
Arguments []PromptArgument `json:"arguments,omitempty"`
Tags []string `json:"tags,omitempty"`
// Organizational fields (camelCase per API spec)
TeamID *string `json:"teamId,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
}
// PromptListOptions specifies the optional parameters to the
// PromptsService.List method.
type PromptListOptions struct {
ListOptions
// IncludeInactive includes inactive prompts in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
// Tags filters prompts by tags (comma-separated)
Tags string `url:"tags,omitempty"`
// TeamID filters prompts by team ID
TeamID string `url:"team_id,omitempty"`
// Visibility filters prompts by visibility (public, private, etc.)
Visibility string `url:"visibility,omitempty"`
}
// PromptCreateOptions specifies additional options for creating a prompt.
// These fields are placed at the top level of the request wrapper.
type PromptCreateOptions struct {
TeamID *string
Visibility *string
}
// Agent represents an A2A (Agent-to-Agent) agent in the ContextForge API.
// A2A agents enable inter-agent communication using the ContextForge A2A protocol.
type Agent struct {
// Core fields
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Description *string `json:"description,omitempty"`
EndpointURL string `json:"endpointUrl"`
AgentType string `json:"agentType"`
ProtocolVersion string `json:"protocolVersion"`
Capabilities map[string]any `json:"capabilities,omitempty"`
Config map[string]any `json:"config,omitempty"`
AuthType *string `json:"authType,omitempty"`
OAuthConfig map[string]any `json:"oauthConfig,omitempty"`
AuthQueryParamKey *string `json:"authQueryParamKey,omitempty"`
AuthQueryParamValueMasked *string `json:"authQueryParamValueMasked,omitempty"`
Enabled bool `json:"enabled"`
Reachable bool `json:"reachable"`
// Timestamps
CreatedAt *Timestamp `json:"createdAt,omitempty"`
UpdatedAt *Timestamp `json:"updatedAt,omitempty"`
LastInteraction *Timestamp `json:"lastInteraction,omitempty"`
// Organizational fields
Tags []Tag `json:"tags,omitempty"`
Metrics *AgentMetrics `json:"metrics,omitempty"`
TeamID *string `json:"teamId,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
// Metadata fields (read-only)
CreatedBy *string `json:"createdBy,omitempty"`
CreatedFromIP *string `json:"createdFromIp,omitempty"`
CreatedVia *string `json:"createdVia,omitempty"`
CreatedUserAgent *string `json:"createdUserAgent,omitempty"`
ModifiedBy *string `json:"modifiedBy,omitempty"`
ModifiedFromIP *string `json:"modifiedFromIp,omitempty"`
ModifiedVia *string `json:"modifiedVia,omitempty"`
ModifiedUserAgent *string `json:"modifiedUserAgent,omitempty"`
ImportBatchID *string `json:"importBatchId,omitempty"`
FederationSource *string `json:"federationSource,omitempty"`
Version *int `json:"version,omitempty"`
}
// AgentMetrics represents performance statistics for an agent.
type AgentMetrics struct {
TotalExecutions int `json:"totalExecutions"`
SuccessfulExecutions int `json:"successfulExecutions"`
FailedExecutions int `json:"failedExecutions"`
FailureRate float64 `json:"failureRate"`
MinResponseTime *float64 `json:"minResponseTime,omitempty"`
MaxResponseTime *float64 `json:"maxResponseTime,omitempty"`
AvgResponseTime *float64 `json:"avgResponseTime,omitempty"`
LastExecutionTime *Timestamp `json:"lastExecutionTime,omitempty"`
}
// AgentCreate represents the request body for creating an A2A agent.
// Note: Uses snake_case field names as required by the API.
type AgentCreate struct {
// Required fields
Name string `json:"name"`
EndpointURL string `json:"endpoint_url"`
// Optional core fields
Slug *string `json:"slug,omitempty"`
Description *string `json:"description,omitempty"`
AgentType string `json:"agent_type,omitempty"` // default: "generic"
ProtocolVersion string `json:"protocol_version,omitempty"` // default: "1.0"
Capabilities map[string]any `json:"capabilities,omitempty"`
Config map[string]any `json:"config,omitempty"`
// Authentication fields
AuthType *string `json:"auth_type,omitempty"`
AuthValue *string `json:"auth_value,omitempty"` // Will be encrypted by API
OAuthConfig map[string]any `json:"oauth_config,omitempty"`
AuthQueryParamKey *string `json:"auth_query_param_key,omitempty"`
AuthQueryParamValue *string `json:"auth_query_param_value,omitempty"`
// Organizational fields (snake_case)
Tags []string `json:"tags,omitempty"`
TeamID *string `json:"team_id,omitempty"`
OwnerEmail *string `json:"owner_email,omitempty"`
Visibility *string `json:"visibility,omitempty"` // default: "public"
}
// AgentUpdate represents the request body for updating an agent.
//
// All fields are optional. The SDK uses a three-state semantics pattern:
// - nil pointer/slice: field will not be updated (omitted from request)
// - pointer to zero value or empty slice: field will be cleared/set to empty
// - pointer to value or populated slice: field will be set to that value
//
// Note: Uses camelCase field names as required by the API.
type AgentUpdate struct {
// All fields optional (camelCase per API spec)
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
EndpointURL *string `json:"endpointUrl,omitempty"`
AgentType *string `json:"agentType,omitempty"`
ProtocolVersion *string `json:"protocolVersion,omitempty"`
Capabilities map[string]any `json:"capabilities,omitempty"`
Config map[string]any `json:"config,omitempty"`
AuthType *string `json:"authType,omitempty"`
AuthValue *string `json:"authValue,omitempty"`
OAuthConfig map[string]any `json:"oauthConfig,omitempty"`
AuthQueryParamKey *string `json:"authQueryParamKey,omitempty"`
AuthQueryParamValue *string `json:"authQueryParamValue,omitempty"`
Tags []string `json:"tags,omitempty"`
TeamID *string `json:"teamId,omitempty"`
OwnerEmail *string `json:"ownerEmail,omitempty"`
Visibility *string `json:"visibility,omitempty"`
}
// AgentListOptions specifies the optional parameters to the
// AgentsService.List method.
// Note: Upstream v1.0.0-BETA-2 supports cursor pagination. Skip remains
// available for backward compatibility.
type AgentListOptions struct {
// Skip specifies the number of items to skip (offset)
// Deprecated: Upstream v1.0.0-BETA-2 uses cursor pagination.
Skip int `url:"skip,omitempty"`
// Limit specifies the maximum number of items to return.
Limit int `url:"limit,omitempty"`
// Cursor is an opaque string used for pagination.
Cursor string `url:"cursor,omitempty"`
// IncludePagination requests body-based pagination metadata in responses.
IncludePagination bool `url:"include_pagination,omitempty"`
// IncludeInactive includes inactive agents in the results
IncludeInactive bool `url:"include_inactive,omitempty"`
// Tags filters agents by tags (comma-separated)
Tags string `url:"tags,omitempty"`
// TeamID filters agents by team ID
TeamID string `url:"team_id,omitempty"`
// Visibility filters agents by visibility (public, private, etc.)
Visibility string `url:"visibility,omitempty"`
}
// AgentCreateOptions specifies additional options for creating an agent.
// These fields are placed at the top level of the request wrapper.
type AgentCreateOptions struct {
TeamID *string
Visibility *string
}
// AgentInvokeRequest represents the request body for invoking an A2A agent.
type AgentInvokeRequest struct {
Parameters map[string]any `json:"parameters,omitempty"`
InteractionType string `json:"interaction_type,omitempty"` // default: "query"
}
// ResourceInfoOptions specifies optional parameters for ResourcesService.GetInfo.
type ResourceInfoOptions struct {
IncludeInactive bool `url:"include_inactive,omitempty"`
}
// GatewayRefreshOptions specifies optional parameters for GatewaysService.RefreshTools.
type GatewayRefreshOptions struct {
IncludeResources bool `url:"include_resources,omitempty"`
IncludePrompts bool `url:"include_prompts,omitempty"`
}
// GatewayRefreshResponse represents the response from manual gateway refresh.
type GatewayRefreshResponse struct {
GatewayID string `json:"gateway_id"`
Success bool `json:"success"`
Error *string `json:"error,omitempty"`
ToolsAdded int `json:"tools_added,omitempty"`
ToolsUpdated int `json:"tools_updated,omitempty"`
ToolsRemoved int `json:"tools_removed,omitempty"`
ResourcesAdded int `json:"resources_added,omitempty"`
ResourcesUpdated int `json:"resources_updated,omitempty"`
ResourcesRemoved int `json:"resources_removed,omitempty"`
PromptsAdded int `json:"prompts_added,omitempty"`
PromptsUpdated int `json:"prompts_updated,omitempty"`
PromptsRemoved int `json:"prompts_removed,omitempty"`
ValidationErrors []string `json:"validation_errors,omitempty"`
DurationMS float64 `json:"duration_ms,omitempty"`
RefreshedAt *Timestamp `json:"refreshed_at,omitempty"`
}
// CancellationRequest represents a cancellation request payload.
type CancellationRequest struct {
RequestID string `json:"requestId"`
Reason *string `json:"reason,omitempty"`
}
// CancellationResponse represents the response from cancellation requests.
type CancellationResponse struct {
Status string `json:"status"`
RequestID string `json:"requestId"`
Reason *string `json:"reason,omitempty"`
}
// CancellationStatus represents cancellation status details for a run.
type CancellationStatus struct {
Name *string `json:"name,omitempty"`
RegisteredAt *float64 `json:"registered_at,omitempty"`
Cancelled bool `json:"cancelled,omitempty"`
CancelledAt *float64 `json:"cancelled_at,omitempty"`
CancelReason *string `json:"cancel_reason,omitempty"`
}
// Team represents a ContextForge team.
type Team struct {